我的意思是功能,对不起!
使用下面的代码,它有几个做不同工作的类。问题是,既然他们从不互相打电话,他们按什么顺序运行?
它们同时运行吗?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Moving extends JPanel implements ActionListener {
int x, y;
Timer timer;
Moving() {
x = 0;
y = 0;
timer = new Timer(10, this);
}
public void actionPerformed(ActionEvent e) {
x += 1;
y += 1;
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (x > 1080 && y > 880) {
x = 0;
y = 0;
} else {
g.fillOval(x, y, 40, 40);
}
}
public static void main(String[] args) {
JFrame f = new JFrame("Moving");
f.setBackground(Color.GREEN);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Moving m = new Moving();
f.add(m);
f.setSize(1100, 900);
f.setVisible(true);
m.timer.start();
}
}