我在单击按钮时尝试在TextArea中设置文本,但没有显示任何文本。我该怎么办?
我想从文本字段中找到该数字的所有素数,但textarea没有响应?
package primnum;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Pframe extends JFrame {
private JLabel l1,l2, l3;
private JTextField f1 ;
private JButton b;
private JTextArea t;
private JPanel p ,p1,p2;
private String s, s2, s3;
private int m ;
private Font f;
public Pframe(){
super("Prime Numbers");
//setLayout(new GridLayout(3,1));
s = new String("Enter a Number (N)");
f = new Font("SanSarif" , Font.BOLD,14);
l1 = new JLabel(s);
l3=new JLabel(" ");
l1.setFont(f);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(l1);
f1 = new JTextField(20);
p.add(f1);
add(p,BorderLayout.NORTH);
p1 = new JPanel();
p1.setLayout(new GridLayout(4,1));
b = new JButton("Find Primes");
b.setSize(1, 3);
p1.add(l3);
p1.add(b);
add(p1,BorderLayout.CENTER);
l2 = new JLabel(" List Of Prime Numbers Less than N");
l2.setFont(f);
p2 =new JPanel();
t = new JTextArea(null,20,60);
t.setEditable(false);
p2.add(l2,BorderLayout.NORTH);
p2.add(new JScrollPane(t),BorderLayout.SOUTH);
add(p2,BorderLayout.SOUTH);
b.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(f1 == null)
JOptionPane.showMessageDialog(null, "UNVALID NUMBER","",JOptionPane.ERROR_MESSAGE);
else{
s2 = f1.getText();
m = Integer.parseInt(s2);
for(int i = 2 ; i<= m ;i++ ){
for (int j=2; j<=i;j++){
if(j==i){
t.append(""+i+"\n");//display the prime numbers in textarea
}
if(i%j==0)
break;
}
}
}
}
});
}
}