import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class twobuttons
{
int x=70;
int y=70;
public static void main(String args[])
{
twobuttons gui =new twobuttons();
gui.go();
}
public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mydraw drawpanel = new mydraw();
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(50);
}
catch(Exception ex)
{
}
}
}
class mydraw extends JPanel
{
public void paintconponent(Graphics g)
{
g.setColor(Color.green);
g.fillOval(x, y, 40, 40);
}
}
}
this is a code from the Head First Java,chapter 12,p384(I am reading the Chinese edition ,maybe it's not in the same page in the English edition.)If successful,there should be a dot running from the left corner to the right corner,however,I can't see anything in the window.