Advertisement
Yehonatan

JPanel repainting

Nov 10th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. public class Test
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         JFrame f = new JFrame("test");
  6.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  7.             f.add(new Circle());
  8.             f.pack();
  9.             f.setVisible(true);
  10.             f.setLocationRelativeTo(null);  //o מיקום החלון במרכז המסך
  11.     }
  12. }
  13.  
  14. public class Circle extends JPanel
  15. {
  16.     public JPanel()
  17.     {
  18.          setPreferredSize(new Dimension(500,500));
  19.     }
  20.    
  21.  
  22.     @override
  23.     public void paintComponent(Graphics g)
  24.     {
  25.         super.paintComponent(g);
  26.         Graphics2D g2d = (Graphics2D) g;
  27.  
  28.         g2d.drawOval(200, 200, 100, 100);
  29.        
  30.         //If you want to call it again
  31.         //repaint();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement