复制代码
1 /*2 使用java实现持续移动的小球
3 */
4
5 package jframe;
6
7 import java.awt.Color;
8 import java.awt.Graphics;
9
10 import javax.swing.JFrame;
11
12 public class JFrameTest extends JFrame{
13 //定义移动变量
14 int x = 0;
15 int y = 0;
16 int m = 1;
17 int n = 1;
18 //主函数
19 public static void main(String[] args) {
20 new JFrameTest();
21 }
22 //使用构造器创建窗体并设置
23 public JFrameTest(){
24 this.setVisible(true);
25 this.setSize(500,500);
26 this.setDefaultCloseOperation(3);
27 this.setLocation(400, 100);
28 this.setResizable(false);
29 this.setTitle("测试框架");
30 move();
31 }
32 //重写画图方法
33 @Override
34 public void paint(Graph