java - Updating String variable in JLabel in JFrame -



java - Updating String variable in JLabel in JFrame -

i have got little problem. have created 2 jframes, , in main 1 show string name. in other 1 can provide name. , when save 'name' variable name doesn't update in main frame. how update frame?

public class main extends jframe { iframe frame = new iframe ("main"); jbutton button_name = new jbutton("enter name"); iframe frame_name = new iframe ("what name?"); point center = graphicsenvironment.getlocalgraphicsenvironment().getcenterpoint(); //get center of screen static image icon = toolkit.getdefaulttoolkit().getimage("icon.png"); buttonlistener button_listen = new buttonlistener(); /**************************************************************************/ string name = new string(); jbutton button_get_name = new jbutton("ok"); jtextfield field_name = new jtextfield(15); jpanel panel_name = new jpanel(); /**************************************************************************/ public main(){ this.seticonimage(icon); button_name.addactionlistener(button_listen); button_get_name.addactionlistener(button_listen); jframe.setdefaultlookandfeeldecorated(true); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setlayout(new gridlayout(4,1)); frame.add(new jlabel (name, swingconstants.center)); frame.add(button_name); frame.add(new jlabel ("table 2", swingconstants.center)); frame.add(panel_name); frame.setbounds(center.x - 400 / 2, center.y - 400 / 2, 400, 400); //set window in center of screen frame.setvisible(true); /**********************************************************************/ panel_name.setbackground(color.cyan); /**********************************************************************/ } /** * @param args command line arguments */ public static void main(string[] args) { new main(); } //class responsible detectin button pushed public class buttonlistener implements actionlistener { @override public void actionperformed(actionevent e) { if (e.getsource() == button_name){ createframename(); } if (e.getsource() == button_get_name){ getname(); } } } //creates frame name provide public void createframename() { int frame_name_width = 280; int frame_name_height = 100; frame.dispose(); frame_name.setbounds(center.x - frame_name_width / 2, center.y - frame_name_height / 2, frame_name_width, frame_name_height); frame_name.setlayout(new gridlayout(2,1)); frame_name.add(field_name); frame_name.add(button_get_name); frame_name.setalwaysontop(true); frame_name.setvisible(true); } public void getname() { name = field_name.gettext(); frame_name.dispose(); frame.setvisible(true); system.out.println(name); } }

java swing

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -