为什么按下侦听键,程序没反应.望各位大虾指点下,先谢了.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class lucky extends JApplet implements ActionListener{
int num;
JLabel label1,label2;
JTextField input;
JButton sure;
int n,randomnum1;
public void init()
{ int num;
Container c=getContentPane();
c.setLayout(new FlowLayout()); label1=new JLabel("please enter:");
c.add(label1); input=new JTextField(5);
c.add(input); label2=new JLabel();
c.add(label2); sure=new JButton("sure");
sure.addActionListener(this);
c.add(sure);
if(!(input.getText()).equals(""))
num=Integer.parseInt(input.getText());
else
num=0;
}
public void actionPerformed(ActionEvent e)
{ play();
}public void play()
{
randomnum1=shu();
for(n=6;n<=1;n--)
{ if(num==randomnum1)
{label2.setText("guess right");
break;
}
else{
if(num>randomnum1)
label2.setText("比所猜的数大,继续");
else
label2.setText("比所猜的数小,继续");
input.setText("");}
}
}public int shu(){
int randomnum;randomnum=1+(int)(Math.random()*100000);
return randomnum;}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class lucky extends JApplet implements ActionListener{
int num;
JLabel label1,label2;
JTextField input;
JButton sure;
int n,randomnum1;
public void init()
{ int num;
Container c=getContentPane();
c.setLayout(new FlowLayout()); label1=new JLabel("please enter:");
c.add(label1); input=new JTextField(5);
c.add(input); label2=new JLabel();
c.add(label2); sure=new JButton("sure");
sure.addActionListener(this);
c.add(sure);
if(!(input.getText()).equals(""))
num=Integer.parseInt(input.getText());
else
num=0;
}
public void actionPerformed(ActionEvent e)
{ play();
}public void play()
{
randomnum1=shu();
for(n=6;n<=1;n--)
{ if(num==randomnum1)
{label2.setText("guess right");
break;
}
else{
if(num>randomnum1)
label2.setText("比所猜的数大,继续");
else
label2.setText("比所猜的数小,继续");
input.setText("");}
}
}public int shu(){
int randomnum;randomnum=1+(int)(Math.random()*100000);
return randomnum;}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货