📄 pinballgame.java
字号:
//// PinBallGame class, first version//// From Chapter 7 of// Understanging Object-Oriented Programming with Java// Written by Tim Budd// Published by Addison-Wesley Longman//// See ftp://ftp.cs.orst.edu/pub/budd/java/ReadMe.html // for further information////import java.awt.*;import java.awt.event.*;import java.util.Vector;public class PinBallGame extends Frame { public static void main (String [ ] args) { PinBallGame world = new PinBallGame(); world.show(); } public static final int FrameWidth = 400; public static final int FrameHeight = 400; private Vector balls; public PinBallGame () { setTitle ("Pin Ball Construction Kit"); setSize (FrameWidth, FrameHeight); balls = new Vector(); addMouseListener (new MouseKeeper()); } private class PinBallThread extends Thread { private Ball theBall; public PinBallThread (Ball aBall) { theBall = aBall; } public void run () { while (theBall.y() < FrameHeight) { theBall.move (); repaint(); try { sleep(10); } catch (InterruptedException e) { System.exit(0); } } } } private class MouseKeeper extends MouseAdapter { public void mousePressed (MouseEvent e) { int x = e.getX(); int y = e.getY(); if ((x > FrameWidth-40) && (y > FrameHeight -40)) { PinBall newBall = new PinBall(e.getX(), e.getY()); balls.addElement (newBall); Thread newThread = new PinBallThread (newBall); newThread.start(); } } } public void paint (Graphics g) { g.setColor (Color.white); g.fillRect (FrameWidth-40, FrameHeight-40, 30, 30); g.setColor (Color.red); g.fillOval (FrameWidth-40, FrameHeight-40, 30, 30); // draw balls for (int i = 0; i < balls.size(); i++) { Ball aBall = (Ball) balls.elementAt(i); aBall.paint(g); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -