- 论坛徽章:
- 0
|
本帖最后由 yyangh 于 2010-10-15 01:25 编辑
为什么按按钮没有反应的呢?
代码是这样的:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Mumber extends Applet
{
static JTextArea startn, endn,keyn , result;
static JButton button;
look k = new look();
public void init()
{
this.setSize(800,600);
JPanel window = new JPanel();
JLabel title = new JLabel("计算起始数到终止数是因子倍数的数");
JLabel slabel = new JLabel("开始数");
JLabel elabel = new JLabel("结束数");
JLabel klabel = new JLabel("因子");
JLabel rlabel = new JLabel("计算结果");
JTextArea startn = new JTextArea();
JTextArea endn = new JTextArea();
JTextArea keyn = new JTextArea();
JTextArea result = new JTextArea();
result.setText("teset");
JButton button = new JButton("开始计算");
window.setLayout(new GridLayout(20,15));
window.add(title);
window.add(new JLabel());
window.add(slabel);window.add(startn);
window.add(new JLabel());
window.add(elabel);
window.add(new JLabel());
window.add(endn);
window.add(klabel);
window.add(keyn);
window.add(new JLabel());
window.add(rlabel); window.add(result);
window.add(button);
add(window,BorderLayout.CENTER);
setVisible(true);
button.addActionListener(k);
}
}
class look implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Mumber.button)
{
if(Mumber.startn.getText() == null || Mumber.endn.getText() == null || Mumber.keyn.getText() ==null )
{
Mumber.result.setText("输入数不能为空!");
}
else
{
int start = Integer.parseInt(Mumber.startn.getText());
int end = Integer.parseInt(Mumber.endn.getText());
int key = Integer.parseInt(Mumber.keyn.getText());
for(int s=start;s<end;s++)
{
if(s%key == 0)
{
Mumber.result.append(String.valueOf(s));
Mumber.result.append(" ");
}
}
}
}
}
} |
|