Nemesis
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
阅读:1114回复:15

[求助]问个JAVA程序

楼主#
更多 发布于:2004-12-31 11:02
知道的请回帖! -------------------- By Quakers,For Quakers!
http://www.q3acn.com/
http://www.unreal.com.cn/
By Quakers,For Quakers! http://www.q3acn.com/ http://www.unreal.com.cn/
啊咿呀
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
1C#
发布于:2004-12-31 11:05
Re:[求助]问个JAVA程序
package thread2;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet1 extends Applet implements Runnable
{
  Label label1 = new Label();
  Label label2 = new Label();
  TextField textField1 = new TextField();
  TextField textField2 = new TextField();
  Thread thread1,thread2;
  int count1=0,count2=0;
  public void init()
    {
    this.setLayout(null);
    label1.setBounds(new Rectangle(52, 86, 83, 23));
    label1.setText("第一个线程");
    label2.setBounds(new Rectangle(53, 116, 85, 35));
    label2.setText("第二个线程");
    textField1.setBounds(new Rectangle(143, 82, 227, 29));
    textField1.setText("textField1");
    textField2.setBounds(new Rectangle(143, 121, 230, 27));
    textField2.setText("textField2");
    this.add(label1, null);
    this.add(label2, null);
    this.add(textField1, null);
    this.add(textField2, null);
  }
  public void start()
  { thread1=new Thread(this,"FirstThread");
    thread2=new Thread(this,"SecondThread");
    thread1.start();
    thread2.start();
  }
  public void run()
  {String curRunning;
   while(true)
   {try{
    Thread.sleep((int)(Math.random()*30000));
    }catch(InterruptedException e){}

   curRunning=Thread.currentThread().getName();
   if(curRunning.equals("FirstThread"))
   {count1++;
    textField1.setText("线程第"+count1+"次被调用");
   }
   else
   {count2++;
    textField2.setText("线程第"+count2+"次被调用");
    }
    }}
}
Nemesis
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
2C#
发布于:2004-12-31 11:06
Re:[求助]问个JAVA程序
还有没?都贴上! -------------------- By Quakers,For Quakers!
http://www.q3acn.com/
http://www.unreal.com.cn/
By Quakers,For Quakers! http://www.q3acn.com/ http://www.unreal.com.cn/
啊咿呀
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
3C#
发布于:2004-12-31 11:09
Re:[求助]问个JAVA程序
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.util.*;


public class BallThread extends Frame
{
     public BallThread()
     {
         setSize(300,200);
         setTitle("多线程动画");

         addWindowListener
             (new WindowAdapter()
                  {
                   public void windowClosing(WindowEvent e){System.exit(0);}
                  }
             );
         final MainPanel canvas=new MainPanel();
         canvas.balls=new Vector();
         add((Panel)canvas,"Center") ;
         Panel p=new Panel();


         addButton(p,"Start",new ActionListener()
                                 {
                                     public void actionPerformed(ActionEvent evt)
                                         {
                                             Ball b=new Ball(canvas);
                                             canvas.balls.add(b);
                                             b.start();
                                         }
                                  }
                  );

        addButton(p,"Close",new ActionListener()
                                {
                                    public  void actionPerformed(ActionEvent evt)
                                        {
                                             canvas.setVisible(false);
                                             System.exit(0);
                                        }
                                }
                  );
         add(p,"South");
    }




    class MainPanel extends Panel
    {
        public Vector balls;
        synchronized public void paint(Graphics g){paintBalls();}
        public void paintBalls()
        {
            Enumeration ballCollection =balls.elements();
            while(ballCollection.hasMoreElements() )
            {
                Ball ball=(Ball)ballCollection.nextElement();
                ball.draw();
            }
        }
    }


    public  void addButton(Container c,String title,ActionListener a)
    {
         Button b=new Button(title);
         c.add(b);
         b.addActionListener(a);
    }


    class Ball extends Thread
    {
        MainPanel mainpanel;
        int XSIZE=10;
        int YSIZE=10;
        private int x=0;
        private int y=0;
        private int dx=2;
        private int dy=2;
        public Ball(MainPanel b){ mainpanel=b;}
        public void draw()
        {
            Graphics g=mainpanel.getGraphics();
            g.fillOval(x,y,XSIZE,YSIZE);
            g.dispose();
        }
        public void move()
        {
            if (!mainpanel.isVisible() )  return;
            x+=dx;
            y+=dy;
            Dimension d=mainpanel.getSize();
            if(x<0){x=0;dx=-dx;}
            if(y<0){y=0;dy=-dy;}
            if(x+XSIZE>=d.width ) {x=d.width -XSIZE;dx=-dx;}
            if(y+YSIZE>=d.height ) {y=d.height -YSIZE;dy=-dy;}
            mainpanel.repaint();
        }
        public void run()
        {
            try {
                draw();
                for(int i=0;i<=1000;i++)
                {
                    move();
                    sleep(50);
                }
                }catch(Exception e){}
        }
    }


    public static void main(String[] args)
    {
        Frame frame=new BallThread();
        frame.show();
    }
}
Nemesis
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
4C#
发布于:2004-12-31 11:12
Re:[求助]问个JAVA程序
Yeah!
Go on!! -------------------- By Quakers,For Quakers!
http://gamer.q3acn.com/
http://www.unreal.com.cn/
By Quakers,For Quakers! http://www.q3acn.com/ http://www.unreal.com.cn/
啊咿呀
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
5C#
发布于:2004-12-31 11:14
Re:[求助]问个JAVA程序
package thread3;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


public class Applet1 extends Applet implements Runnable
{ Thread ci;
  public void start()
  {if(ci==null)
   ci=new Thread(this);
   ci.start();
   }
  public void run()
  {while(ci!=null)
  {repaint();
   try{
   ci.sleep(1000);
   }catch(InterruptedException e){}
   }}
  public void paint(Graphics g)
  {double i=Math.random();
   if(i<0.5)
   g.setColor(Color.red);
   else
   g.setColor(Color.blue);
   g.fillOval(100,100,(int)(100*i),(int)(100*i));
   }
   public void stop()
   {ci.yield();
    ci=null;}
}
TDH少堂主
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
6C#
发布于:2004-12-31 11:15
Re:[求助]问个JAVA程序
package time;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet1 extends Applet implements Runnable
{ int h,m,s;
  int x1,y1,x2,y2;
  int R=10,x0,y0;
  Date  d;
  Font FaceFont;
  Color handColor,numberColor;
  Thread timer;
  public void init()
  { try {
            setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),16)));
               //16进制
        } catch (Exception E) { }
    try {
            R = Integer.parseInt(getParameter("radus"),10);
        } catch (Exception E) {}
    try {
            handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),16));
        } catch (Exception E) { }
    try {
            numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),16));
        } catch (Exception E) { }
    x0=R;
    y0=R;
   FaceFont = new Font("Serif", Font.PLAIN, 14);
  }
  public void paint(Graphics g)
  { float q;
    d=new Date();

       SimpleDateFormat formatter = new SimpleDateFormat("s",Locale.getDefault());
        try {
            s = Integer.parseInt(formatter.format(d));
        } catch (NumberFormatException n) {
            s = 0;
        }
        formatter.applyPattern("m");
        try {
            m = Integer.parseInt(formatter.format(d));
        } catch (NumberFormatException n) {
            m = 10;
        }
        formatter.applyPattern("h");
        try {
            h = Integer.parseInt(formatter.format(d));
        } catch (NumberFormatException n) {
            h = 10;
        }
        formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");

    //h=d.getHours();
    //m=d.getMinutes();
    //s=d.getSeconds();
    g.setColor(handColor);
    g.drawOval(0,0,2*R,2*R);
    for(int i=0;i<12;i++)
    {y1=(int)(y0-Math.cos(i*30*3.1415926f/180)*R*(float)8/10);
     x1=(int)(x0+Math.sin(i*30*3.1415926f/180)*R*(float)8/10);
     y2=(int)(y0-Math.cos(i*30*3.1415926f/180)*R);
     x2=(int)(x0+Math.sin(i*30*3.1415926f/180)*R);
     g.drawLine(x1,y1,x2,y2);
    }
    q=(h*30+(float)m/2)*3.1415926f/180;
    y2=(int)(y0-Math.cos(q)*R*(float)5/10);
    x2=(int)(x0+Math.sin(q)*R*(float)5/10);
    g.drawLine(x0,y0,x2,y2);
    q=(m*6+(float)s/10)*3.1415926f/180;
    y2=(int)(y0-Math.cos(q)*R*(float)6/10);
    x2=(int)(x0+Math.sin(q)*R*(float)6/10);
    g.drawLine(x0,y0,x2,y2);
    q=(s*6)*3.1415926f/180;
    y2=(int)(y0-Math.cos(q)*R*(float)7/10);
    x2=(int)(x0+Math.sin(q)*R*(float)7/10);
    g.drawLine(x0,y0,x2,y2);
    g.drawString(String.valueOf(d).toString(),10,2*R+20);
 }
   public void stop() {
        timer = null;
    }

   public void run() {
        Thread me = Thread.currentThread();
        while (timer == me) {
            try {
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
            }
            repaint();
        }
    }

   //public void update(Graphics g) {
   //    paint(g);
    //}

  public void start()
  {timer=new Thread(this);
   timer.start();
   }
}
-------------------- 印院JAVA第一———JAVA王子!!

我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
印院JAVA第一———JAVA王子!! 我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
Nemesis
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
7C#
发布于:2004-12-31 11:16
Re:[求助]问个JAVA程序
Good!
Continue!! -------------------- By Quakers,For Quakers!
http://gamer.q3acn.com/
http://www.unreal.com.cn/
By Quakers,For Quakers! http://www.q3acn.com/ http://www.unreal.com.cn/
TDH少堂主
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
8C#
发布于:2004-12-31 11:20
Re:[求助]问个JAVA程序
package rlsfk;

import javax.swing.UIManager;

public class Application1
{
  boolean packFrame = false;

  //Construct the application
  public Application1()
  {
    Frame1 frame = new Frame1();
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame)
      frame.pack();
    else
      frame.validate();
    frame.setVisible(true);
  }

  //Main method
  public static void main(String[] args)
  {
    try
    {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e)
    {
    }
    new Application1();
  }
} -------------------- 印院JAVA第一———JAVA王子!!

我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
印院JAVA第一———JAVA王子!! 我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
Nemesis
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
9C#
发布于:2004-12-31 11:20
Re:[求助]问个JAVA程序
望斑竹把此贴作为教学贴置顶! -------------------- By Quakers,For Quakers!
http://gamer.q3acn.com/
http://www.unreal.com.cn/
By Quakers,For Quakers! http://www.q3acn.com/ http://www.unreal.com.cn/
TDH少堂主
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
10C#
发布于:2004-12-31 11:20
Re:[求助]问个JAVA程序
package rlsfk;

import javax.swing.UIManager;

public class Application1
{
  boolean packFrame = false;

  //Construct the application
  public Application1()
  {
    Frame1 frame = new Frame1();
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame)
      frame.pack();
    else
      frame.validate();
    frame.setVisible(true);
  }

  //Main method
  public static void main(String[] args)
  {
    try
    {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e)
    {
    }
    new Application1();
  }
} -------------------- 印院JAVA第一———JAVA王子!!

我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
印院JAVA第一———JAVA王子!! 我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
TDH少堂主
普通会员
普通会员
  • 铜币0枚
  • 威望0点
  • 贡献值0点
11C#
发布于:2004-12-31 11:24
Re:[求助]问个JAVA程序
牛B吗? -------------------- 印院JAVA第一———JAVA王子!!

我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
印院JAVA第一———JAVA王子!! 我的最爱安东尼奥.卡萨诺(Antonio Cassano) !!!
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
12C#
发布于:2004-12-31 17:49
Re:[求助]问个JAVA程序
Topic:[求助]问个JAVA程序
Content:知道的请回帖!

楼主要干嘛? -------------------- [a=http://go2west.512j.com/]西へ·独自旅行人のBLOG[/a]
罪惡之門。
    Username: █████████
  
    Password:  █████████
                Don't ask for my
                   password for 2 weeks.
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
lijiannan_1981
著名写手
著名写手
  • 铜币15枚
  • 威望0点
  • 贡献值0点
13C#
发布于:2005-01-05 09:33
Re:[求助]问个JAVA程序
[fly]垃圾![/fly]
无。
tsx
tsx
知名人士
知名人士
  • 铜币0枚
  • 威望0点
  • 贡献值0点
14C#
发布于:2005-01-21 15:31
Re:[求助]问个JAVA程序
楼主到底想问什么嘛?[em045] -------------------- 别拿你的脾气,挑战我的个性
别拿你的脾气,挑战我的个性
你令我烦躁
写手
写手
  • 铜币0枚
  • 威望0点
  • 贡献值0点
15C#
发布于:2005-01-28 22:56
Re:[求助]问个JAVA程序
我也想知道~ -------------------- [a]http://fengchao.ik8.com[/a]
[img]http://www.wait4c.com/bbs/userfiles/6214/2005060418553165120.jpg[/img]
游客

返回顶部