Quantcast
Channel: OKWAVE 閲覧数の多い質問(Java/253)【本日】
Viewing all articles
Browse latest Browse all 68675

JFrameクラスの挙動に対する推察と質問

$
0
0
JFrameクラスの挙動に対する推察と質問 現在、プログラムでJFrameクラスを使って,Windowを表示させるアプリをつくっているのですが、repaintがうまく動作しません。 コードで説明させていただきますと、 public class Main{   public static void main(String[] args){     Drow drow ;     drow = new Drow();     drow.createFrame();     drow.repaint();//画面は更新されない   } } public class Drow extends JPanel{   JFrame frame;   static Image jpg;   static int x;   static int y;   public void createFrame()    {     frame = new JFrame();     Drow app = new Drow();     frame.getContentPane().add(app);     frame.getContentPane().add( new Drow() );     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setBounds(10, 10, 300, 200);     frame.setTitle("タイトル");     frame.setVisible(true);   }   public void paintComponent(Graphics g){     super.paintComponent(g);     g.drawOval(x, y, 80, 80);   } } このソースのMain文でrepaintを実行させているのですが、画面は更新されません。 このエラーについて自分なりに原因を推察した所、JFrameは自分で自分のクラスのインスタンスを作成しているからではないかと考えました。 なので私がrepaintを実行しても、それは私の作ったdrowインスタンスのpaintComponentが実行されているだけで、JFrameが自動でつくったインスタンスの方には影響がないのだと推察しました。 ここで質問なのですが、私の推察はあっているでしょうか? また、このようなrepaintをMain文で実行したい場合はどのようにしたらよいのでしょうか? お返事お待ちしております。

Viewing all articles
Browse latest Browse all 68675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>