import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.Math;
public class Sushu extends JFrame implements ActionListener{
private JTextField txt1;
private JTextField txt2;
private JTextArea txt3;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JButton btn1;
private JButton btn2;
// - - - -- - - - - -¹¹Ô캯Êý
public Sushu(){
super("ËØÊýÆ÷");
setSize(400,200);
txt1 =new JTextField("",5);
txt2 =new JTextField("",5);
txt3 =new JTextArea(10,5);
lbl1 =new JLabel(" ÏÂÏÞ");
lbl2 =new JLabel("ÉÏÏÞ");
lbl3=new JLabel("½á¹û");
btn1=new JButton("Go");
btn2=new JButton("exit");
Container cp= getContentPane();
cp.setLayout(new GridLayout(4,2));
cp.add(lbl1);
cp.add(txt1);
cp.add(lbl2);
cp.add(txt2);
cp.add(lbl3);
cp.add(txt3);
cp.add(btn1);
cp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
int i=0,j=0;
String str="";
if(e.getSource()==btn1){
for( i=Integer.parseInt(txt1.getText());i<=Integer.parseInt(txt2.getText());i++){
for( j=2;j<i;j++){
if(i%j==0)
break;
}
if(j>=i){
//String str="";
str=str+String.valueOf(i)+" ";
txt3.setText(str);
//txt3.setText("/n");
}
}
}
else dispose();
}
public static void main(String[] args){
Sushu susu =new Sushu();
susu.setVisible(true);
//susu.pack();
}
}很早以前的一个作业 你自己看看吧