java - How to pass values from one JFrame to another JFrame? -
i've created 2 jframes. main jframe contains text area. sub jframe contains drop down list. task pass value i've selected in drop down list , display in text area in main jframe.
code in sub jframe:
private void btnokactionperformed(java.awt.event.actionevent evt) { close(); room=cmbroom.getselecteditem().tostring(); }
code in main jframe:
private void btndisplayactionperformed(java.awt.event.actionevent evt) { roomno r=new roomno(); txtarea2.append("\nroom number: " + r.getroom()); }
import java.awt.*; import javax.swing.*; import java.awt.event.*; class passdata extends jframe { jtextfield text; passdata(){ jlabel l=new jlabel("name: "); text=new jtextfield(20); jbutton b=new jbutton("send"); setlayout(null); l.setbounds(10,10,100,20); text.setbounds(120,10,150,20); b.setbounds(120,40,80,20); add(l); add(text); add(b); setvisible(true); setsize(300,100); b.addactionlistener(new actionlistener(){ public void actionperformed(actionevent e){ string value=text.gettext(); nextpage page=new nextpage(value); page.setvisible(true); } }); } public static void main(string[] args) { new passdata(); } }
Comments
Post a Comment