• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

this animation code does not show o/p

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi frnds... here is a simple animation code which runs but does not show the circle on screen moving.....please help

import javax.swing.*;
import java.awt.*;

public class SimpleAnimation1
{
int x = 70 ; int y = 70;

public static void main(String[] args)
{
SimpleAnimation1 gui = new SimpleAnimation1();
gui.go();
}

public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

MyDrawpanel drawpanel = new MyDrawpanel();

frame.getContentPane().add(drawpanel);
frame.setSize(300,300);
frame.setVisible(true);

for(int i = 0; i < 130; i++)
{
x++; y++;
drawpanel.repaint();

try
{
Thread.sleep(20);//will know the meaning later
}catch (Exception ex){ }
}
}

class MyDrawpanel extends JPanel//an inner class ( nested class)
{
public void paintCompnent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(),this.getHeight());//will replace the green with white
g.setColor(Color.green);
g.fillOval(x,y,40,90);
}
}

}


 
Rancher
Posts: 5127
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried debugging your code?
Put some println() statements in the paint method to see when/if it is called.
Also if you are using java 1.6 look at using the @Override annotation.
 
sivasubramanian nagarajan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friennd,

just checked with a print statement inside the paintComponent() method and it did not print that either.can you help me with the problem..
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint: you don't have a "paintComponent()" method. Norm's suggestion to use the "@Override" annotation is directly related to this (and it works in 1.5, too, not just 1.6.)

Hint #2: computers are very picky about spelling.
 
sivasubramanian nagarajan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friend....

Finally it worked.....paintComponent() method does exist...i had done a silly mistake of writing the paintComponent() incorrectly as paintCompnent()....

Thanks for your help.
tc
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to get in the habit of using the @Override annotation. It prevents this kind of error.
 
sivasubramanian nagarajan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am unaware of @override....can you please explain?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the javadocs for java.lang.Override; it's easy to try out and see its effect.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic