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

📄 littleballs.java~6~

📁 学生信息管理系统,包括成绩查询,成绩排序,用ACCESS做数据库连接
💻 JAVA~6~
字号:
package Chapter1;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class LittleBalls extends Applet implements MouseListener,ActionListener
{
  public static final double PI=3.1415926;      //常数圆周率
  public static final double M=Math.sin(PI/6);  //常数sin(30度)
  public static final double N=Math.cos(PI/6);  //常数cos(30度)
  private static final int WIDTH=1000;           //窗体宽度
  private static final int HEIGHT=600;          //窗体高度
  private static final double V=0.15;           //小球圆心运动速度
  private static final int r=30;                //圆的初始半径
  int t=-176,w=WIDTH/2,h=HEIGHT/2;                 //t单位为毫秒
  int R=0,s=0;                                      //t时刻的半径
  int l1=w-R,l2=h-R;
  int l=(int)(1.2*r);
  int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
  int num=0;
  Button button1,button2;
  private boolean isStandalone = false;
  //Construct the applet
  public LittleBalls()
  {
  }
  public void mousePressed(MouseEvent e) {}
 public void mouseReleased(MouseEvent e) {}
 public void mouseEntered(MouseEvent e) {}
 public void mouseExited(MouseEvent e) {}
 public void mouseClicked(MouseEvent e)
 {
      repaint();
 }

  public void init()
{
button1 = new Button("PLAY");
button2 = new Button("STOP");
button1.addActionListener(this);
button2.addActionListener(this);
add(button1);
add(button2);
button1.setVisible(true);
button2.setVisible(true);
setVisible(true);
addMouseListener(this);
}
  public void actionPerformed(ActionEvent e)
{

}

  public void paint(Graphics g)
  {
    s=(int)(V*t);
    R=(int)(r+0.02*t);
    x1=l1;                     y1=l2-l-s;
    x2=(int)(l1+l*N+N*s);      y2=(int)(l2-l*M-M*s);
    x3=(int)(l1+l*N+N*s);      y3=(int)(l2+l*M+M*s);
    x4=l1;                     y4=l2+l+s;
    x5=(int)(l1-l*N-N*s);      y5=(int)(l2+l*M+M*s);
    x6=(int)(l1-l*N-N*s);      y6=(int)(l2-l*M-M*s);
    Color contentColor []=new  Color[6];
    int RR []=new int [6];
    int GG []=new int [6];
    int BB []=new int [6];
    for(int i=0;i<6;i++)
     {
       RR[i]=(int)(255*Math.random());
       GG[i]=(int)(255*Math.random());
       BB[i]=(int)(255*Math.random());
       contentColor[i]=new Color(RR[i], GG[i], BB[i]);
     }
     if(num==0)
     {
       g.setColor(contentColor[0]);
       g.fillOval(x1, y1, R, R); //画1号圆
       num++;
     }
     else if(num==1)
    {
      g.setColor(contentColor[1]);
      g.fillOval(x2, y2, R, R); //画2号圆
      num++;
    }
    else if(num==2)
    {
      g.setColor(contentColor[2]);
      g.fillOval(x3, y3, R, R); //画3号圆
      num++;
    }
    else if(num==3)
     {
       g.setColor(contentColor[3]);
       g.fillOval(x4, y4, R, R); //画4号圆
       num++;
     }
     else if(num==4)
     {
       g.setColor(contentColor[4]);
       g.fillOval(x5, y5, R, R); //画5号圆
       num++;
     }
     else if(num==5)
     {
       g.setColor(contentColor[5]);
       g.fillOval(x6, y6, R, R); //画6号圆
       num++;
     }
     try
     {
        Thread.sleep(100);
     }
     catch(InterruptedException E)
         {}
      if(t==2224)   t=-176;
      else  t+=100;
          repaint();

  }
}

⌨️ 快捷键说明

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