标签:rap 调试器 mac graph 入门 jvm default system 字节
public static void main(String[] args) {...}
import java.awt.*
import java.swing.*
Image image = Toolkit.getDefaultToolkit().getImage("ImagePath")
public class BallGame extends JFrame() {...}
public class BallGame extends JFrame {
private Image ball = Toolkit.getDefaultToolkit().getImage("image/ball.png");
private Image desk = Toolkit.getDefaultToolkit().getImage("image/background.png");
private double ball_abscissa = 100;
private double ball_ordinate = 100;
private double degree = 3.14/3;
// Load Window
private void launchFrame() {
setSize(558, 320);
// 以屏幕的左顶点为原点,向右为x正方向,向下为y正方向
setLocation(50,50);
setVisible(true);
// 不断重画窗口
while (true) {
// repaint() 调用的 paint() 方法;
repaint();
// 间隔40ms重画一次窗口;
// 需要加上异常处理机制,不然 sleep 方法会报错;
try {
Thread.sleep(40);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Paint Window
public void paint(Graphics graphics) {
System.out.println("Once");
graphics.drawImage(desk, 0, 0, null);
graphics.drawImage(ball, (int)ball_abscissa, (int)ball_ordinate, null);
ball_abscissa += 10*Math.cos(degree);
ball_ordinate += 10*Math.sin(degree);
// 5 代表球的半径
// 40 代表窗口上边框的高度
// 检测上下边界
if (ball_ordinate < 5+40 || ball_ordinate > 320-5)
degree = -degree;
// 检测左右边界
if (ball_abscissa < 5 || ball_abscissa > 558-5)
degree = 3.14 - degree;
}
public static void main(String[] args) {
BallGame game = new BallGame();
game.launchFrame();
}
}
标签:rap 调试器 mac graph 入门 jvm default system 字节
原文地址:https://www.cnblogs.com/rongyupan/p/12670443.html