Results 1 to 2 of 2
  1. #1
    gest is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Question annimation with paintComponent

    1. I want to see all the Points one after another but I see only able to see 1
    point. What shold I change to see all the Points?
    2. In the `System.out` you can see 10 times "change" and then 2 times
    "paintComponent". what should I change that after each time set is
    called it change the "paintComponente" ?

    Java Code:
        public class exampe extends JPanel  
        {
            int x; 
            int y;
        
            public void paintComponent(Graphics g) 
            {
                super.paintComponent(g);
                
                Graphics2D g2 = (Graphics2D) g;
                g2.fillOval(x-2,y-2,4,4);
                System.out.println("paintComponent");        
            }
        
            public void change(int X, int Y)
            {
                x = X;
                y = Y;
                System.out.println("change");
                super.repaint();
            }
               
            public static void main(String args[]) 
            {   
                int e=1;
                    
                JFrame frame = new JFrame("TEST");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    
                exampe ex= new exampe();
                JScrollPane scroll = new JScrollPane(ex);
                frame.getContentPane().add(scroll);
                    
                frame.setSize(400, 300);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                   
                for(int i=0; i< 10; ++i)
                    ex.change(e+i,e+i);         
            }
        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

Similar Threads

  1. paintComponent
    By zock70 in forum AWT / Swing
    Replies: 1
    Last Post: 11-16-2011, 03:19 AM
  2. geting value from paintComponent
    By gedas in forum New To Java
    Replies: 3
    Last Post: 03-21-2011, 07:56 PM
  3. Help with paintComponent!
    By joeyea in forum Java 2D
    Replies: 6
    Last Post: 12-27-2010, 01:59 PM
  4. JPanel PaintComponent
    By capiono in forum AWT / Swing
    Replies: 5
    Last Post: 10-31-2010, 03:36 AM
  5. paint() and paintComponent()
    By goldhouse in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 03:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •