ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2026/1/9 16:03:26ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£
this.name=name; } }
15.ÔÚÏÂÁгÌÐòµÄÖ÷Ïß³Ìmai n ·½·¨ÖУ¬ÓÖ¿ªÊ¼ÔËÐÐÁ˼¸¸öỊ̈߳¿ import java.awt.* ; import java.awt.e vent.*;
class Gxy extends Thread implements Runnable {
Frame f=new Frame(\
TextField text1=new TextField(20 ),text2=new TextField(20 ),text3=new TextField(20 ); double n=0,ÕýÃæ=0,·´Ãæ=0,ÕýÁ¢=0; Gxy() {
f.setLayou t(new FlowLayout( )); f.setSi ze ( 2 00,300); f.setVisib le(true); f.add(text 1); f.add(text 2); f.add(text 3); f.validate ();
f.addWind owListener(new WindowAda pter() {
public void windowClosi ng(WindowEvent e) {
System.exi t(0); } }); }
public void run() {
while(tru e) { n++;
double i=Math.ra ndom(); if(i<0.5) { ÕýÃæ++;
text1.setT ext(\ÕýÃæ³öÏֵįµÂÊ:\ÕýÃæ/n);
}
else if(i==0.5) { ÕýÁ¢++;
text2.setT ext(\ÕýÁ¢³öÏֵįµÂÊ:\ÕýÁ¢/n); } else { ·´Ãæ++;
text3.setT ext(\·´Ãæ³öÏֵįµÂÊ:\·´Ãæ/n); } try {
Thread.sle ep(200); }
catch(Exce ption e) {} } } }
public class E {
public static void main(Strin g args[]) {
Thread t=new Thread(new Gxy()); t.start(); } }