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

📄 ballworld.java

📁 一些java初学者可以借鉴的代码。也是初学者的最好的学习例子
💻 JAVA
字号:
import java.awt.*;
 
public class BallWorld extends Frame
{
 public static void main(String args[])
 {
 BallWorld world =new BallWorld(Color.red);
 world.show();
 }
 
 private static final int FrameWidth = 600;
 private static final int FrameHeight = 400;
 private Ball aBall;
 private int counter=0;
 
 private BallWorld(Color ballcolor)
 {
 setSize(FrameWidth,FrameHeight);
 setTitle("Ball world");
 aBall =new Ball(10,15,5);
 aBall.setColor(ballcolor);
 aBall.setMotion(3.0,6.0);
 }
 
 public void paint(Graphics g)
 {
  aBall.paint(g);
  aBall.move();
  if(aBall.x()<0 || aBall.x()>FrameWidth) 
  aBall.setMotion(-aBall.xMotion(),aBall.yMotion());
  if(aBall.y()<0 || aBall.y()>FrameHeight)
  aBall.setMotion(aBall.xMotion(),-aBall.yMotion());
  if(counter<2000) repaint();
  else System.exit(0);
 }
 
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -