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

📄 runt.java~68~

📁 自动random画线的java applet 小程序源码.
💻 JAVA~68~
字号:
package runt;

import java.applet.*;
import java.awt.*;
import java.util.LinkedList;
import javax.swing.*;


public class runt
    extends Applet implements Runnable {
  boolean isStandalone = false;
  BorderLayout borderLayout1 = new BorderLayout();
  int x2, x = 5;
  int y2, sleepti = 800, dis = 10, y = 150;
  JPanel pp;
  LinkedList ll =new LinkedList();

  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
        (getParameter(key) != null ? getParameter(key) : def);
  }

  //Construct the applet
  // public runt() {    }

  //Initialize the applet
  public void init() {
    try {
      //jbInit();
      Container con = new Container();
       pp = new javax.swing.JPanel();
      this.add(pp);
      points apoints= new points();
      apoints.setx(x);
      apoints.sety(y);
      System.out.println(apoints.getx()+"  apoints  "+apoints.gety());
      ll.add(apoints);
      }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception {

  }

  public void start() {
    new Thread(this).start();
  }
  public int RandomInteger() {
     int n;
     double d = Math.random(); // 0.0  to  1.0
     d = d * 10;
     n = (int) d + 1; // 1 to c  (max. 100)
     if (Math.random() >=0.5)
       return n;
     else
       return -n;
   }

  public void paint(Graphics g){
      points oldpoints=new points();
      oldpoints = (points)ll.getLast();
      y2 = RandomInteger() + oldpoints.gety();
      x2 = oldpoints.getx()+dis;
      points anotherpoints =new points();
      anotherpoints.setx(x2);
      anotherpoints.sety(y2);

      ll.add(anotherpoints);
      g.setColor(Color.black);
       LinkedList newl = ll;
       int account = ll.size();
       int i ;

      for (i=1; i <account ;i++ ){
         points first= (points)ll.get(i-1);
        points second=(points)ll.get(i);
        g.drawLine(first.getx(),first.gety(), second.getx(),second.gety());
        System.out.println(second.getx()+"   "+second.gety());
      }
  }

  public void run() {
    try {
      while (true) {
        Thread.sleep(sleepti);
        repaint();
      }
    }
    catch (Exception e) {
      System.out.println("help");
    }
  }

  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }

  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }

  public class points{
    private int x ;
    private int y ;
    public void points(){}
    public void  points(int ix,int iy){
      x= ix ;
      y =iy ;
    }
    public int getx (){
      return x;
    }
    public int gety (){
      return y;
    }
    public void setx (int ix){
     x =ix;
   }
   public void sety (int iy){
     y=iy;
   }

  }





}

⌨️ 快捷键说明

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