⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pinballpanel1.java

📁 一些JAVA的小程序
💻 JAVA
字号:
import java.awt.event.*;import java.util.Vector;import javax.swing.*;import java.awt.*;public class PinBallPanel extends JPanel {  private Vector balls;   //A vector to hold balls  private PinBallFire fireButton = new PinBallFire(new Point(PinBallGame.FrameWidth-40, PinBallGame.FrameHeight-70));  public PinBallPanel(){    balls = new Vector();    addMouseListener(new MouseKeeper());  }  private class MouseKeeper extends MouseAdapter{    public void mousePressed(MouseEvent e) {	//locate position of mouse cursor when moused clicked      int x = e.getX();      int y = e.getY();	//if mouse clicked within firing region, create new	//ball and thread, and start thread      if (fireButton.includes(x, y)) balls.addElement(fireButton.fire(x, y));    }  }  public void run() {    while (true) {      moveBalls();      repaint();      try {        Thread.sleep(10);      } catch(InterruptedException e) {System.exit(0);}    }  }  private void moveBalls() {    for (int i = 0; i < balls.size(); i++) {      Ball theBall = (Ball) balls.elementAt(i);      if (theBall.y() < PinBallGame.FrameHeight)        theBall.move();    }  }  public void paintComponent(Graphics g) {    super.paintComponent(g); //clear window    fireButton.paint(g);    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 + -