私は3つのクラスを持っているので、私は素晴らしい問題を抱えています:
- WindowFrame-そのクラスはJFrameを拡張し、内部のパネルの1つを表示します。
- WindowPanel-JPanelを拡張するクラスです。そこにレイアウトBoxLayoutがあります。WindowFrameの他のパネルを切り替えたい。
- GButton-通常のボタンのようなクラスですが、bgにテクスチャがあり、add()を使用してWindowPanelに簡単に追加したいと考えています。
public class GButton extends JComponent implements MouseMotionListener, MouseListener{
int x, y , w, h; //the coordinates of button
Graphics2D g2d;
public GButton(int x, int y){
this.x = x; this.y = y;
this.w = 200; this.h = 100;
... //add listeners, loading some information etc
}
@Override
public void paintComponent(Graphics g){
g2d = (Graphics2D) g;
...//loading and draw on g2d
g2d.drawString("asidoaisjdiajsoidj",x,y);
}
//code with using events of mouse and so on
}
そして、ボタンを追加すると、ボタンのテクスチャはyの下50pxになります!次のボタンは、yとのこの違いを大きくしました。なんで?私はヘルプMouseMoveイベントでそれをチェックするのでそれを知っています。画像のサイズなどは悪くありません。なぜそれが機能しないのですか、そしてそれは他の場所で物事をペイントしますか?同じ効果を得る簡単な方法はありますか?お答えください :)