package Game;import java.awt.*;import javax.swing.*;public class Ballgame extends JFrame {//框 Image ball = Toolkit.getDefaultToolkit().getImage("images/ball.png"); Image desk=Toolkit.getDefaultToolkit().getImage("images/desk.jpg");double degree=3.14/3;//弧度 double x=100;//小球的坐标 double y=100; //画窗口的方法 public void paint(Graphics g){ System.out.println("窗口被画了一次!"); g.drawImage(desk,0, 0,null);//先画桌面再画球 g.drawImage(ball, (int)x, (int)y, null);x=x+10*Math.cos(degree);y+=10*Math.sin(degree);if(y>=500-70||y<70){ degree=-degree;}//左右边界if(x<70||x>796){ degree=3.14-degree;} } //窗口加载 void launchFrame(){ setSize(856,500); setLocation(400,400); setVisible(true); //重画窗口 while(true){ repaint();//调用paint try { Thread.sleep(80); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //main方法是程序执行的入口 public static void main(String[] args){ System.out.println(" 我是尚学堂高淇,这个游戏项目让大家体验编程的快感,寓教于乐!"); Ballgame game = new Ballgame(); game.launchFrame(); } }