importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassfengshanextendsJFrame{publicfengshan(){add(newzhuandong());}publicstaticvoidmain(String[]args){feng...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class fengshan extends JFrame{
public fengshan(){
add(new zhuandong());
}
public static void main(String[] args){
fengshan f=new fengshan();
f.setSize(400, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
class zhuandong extends JPanel{
public zhuandong(){
Timer timer=new Timer(1000,new TimerListener());
timer.start();
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
int xcenter=getWidth()/2;
int ycenter=getHeight()/2;
int radius=20;
int x=xcenter-radius;
int y=ycenter-radius;
g.fillArc(x, y, 2*radius,2*radius,0, 30);
g.fillArc(x, y, 2*radius,2*radius,90, 30);
g.fillArc(x, y, 2*radius,2*radius,180, 30);
g.fillArc(x, y, 2*radius,2*radius,270, 30);
}
class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
}
}
展开