import java.awt.*;
import javax.swing.*;
public class BallGame extends JFrame{
Image ballDefaultToolkit().getImage(“images/ball.png”);
Image deskDefaultToolkit().getImage(“images/desk.jpg”);
double x=100;
double y=100;
boolean right=true;
private Image OffScreenImage=null;
public void paint(Graphics g){
if(OffScreenImage==null){
OffScreenImageateImage(856,500);
}
Graphics goffGraphics();
goff.drawImage(desk,0,0,null);goff.drawImage(ball,(int)x,(int)y,null);if(right){x=x+10;}else{x=x-10;}if(x>856-40-30){right=false;}if(x<40){right=true;}g.drawImage(OffScreenImage,0,0, null);
}void launchFrame(){ setSize(856,500);setLocation(50,50);setVisible(true);while(true){repaint();try {Thread.sleep(40);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}public static void main(String[] args ){System.out.println("JOJO的桌游");BallGame game=new BallGame();game.launchFrame();}
}
本文发布于:2024-02-03 02:32:23,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170689874348059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |