java - TextArea not responsing -
i have tried setting text in textarea while clicking on button, no text shows up. can do?
i want find prime numbers number textfield, textarea not responding?
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 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 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 = 2 ; i<= m ;i++ ){ (int j=2; j<=i;j++){ if(j==i){ t.append(""+i+"\n");//display prime numbers in textarea } if(i%j==0) break; } } } } }); } }
Comments
Post a Comment