私はメインクラスとその中にpaintComponentメソッドを持つサブクラスCircleを持っています。サークルを描画するために、そのメソッドをメインクラスに呼び出そうとしていますが、何も表示されません。理由はわかりません。Javaは別のクラスからpaintComponentを描画しません
マイサークルクラス:
public class Circle extends Shape {
Integer rad;
public Circle(int posx,int posy, int rad) {
this.posx = posx;
this.posy = posy;
this.rad = rad;
}
class drawCircle extends JPanel {
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.green);
g.fillOval(posx,posy,rad,rad);
}
}
}
私の主な方法は
public class drawFrame extends JFrame {
JPanel panel1;
JPanel panel2;
Square square1;
Circle circle1;
public drawFrame() {
panel2= new JPanel();
panel1= new JPanel();
int rad = 0;
circle1 = new Circle(posx, posy,rad);
Circle.drawCircle drawCi = circle1.new drawCircle();
add(panel1, BorderLayout.CENTER);
panel1.add(drawCi);
だから基本的に私は、コードの主要な部分のいくつかのスニペットを与えてくれたスニペット。私がやったことは、Circle drawCircle
内部クラスから新しいオブジェクトを作成してmainPanel
に追加して、私の作成した新しいCircleオブジェクトであるmainPanel
の内容をJframeが出力するようにしました。しかし、これは動作しないようです。
答えるために編集を参照してください。不明な点や質問に答えた場合はコメントしてください。 –