swing - Java GUI Input Dialogs are showing up twice -


i have assignment class, , made simple accounting program in java gui. first time working gui in java, , i'm not programmer.

when program runs, user can select 5 jbuttons when clicked takes them new jframe input dialogs, saved strings , doubles. variables set like

variable = joptionpane.showinputdialog("textgoeshere");

my problem after entering values dialogs, pop second time, in loop. user has enter input every dialog twice.

code 1 of buttons:

pcbutton.addactionlistener(new actionlistener()  {   public void actionperformed(actionevent e)   {      jframe pcframe = new jframe("choosing file menu");     pcframe.setsize(760,500);          pcframe.add( new jpanel()           {            public void paintcomponent( graphics g )              {               super.paintcomponent(g);               //action begin----------------------------------------- 

the input dialogs showing twice:

              compname = joptionpane.showinputdialog("what name of business?");               firstname = joptionpane.showinputdialog("what first name?");               lastname = joptionpane.showinputdialog("what last name?");                day = joptionpane.showinputdialog("what day?");               month = joptionpane.showinputdialog("what month?");               year = joptionpane.showinputdialog("what year?");                string filename = joptionpane.showinputdialog("would file 1, 2, or 3? (type in 1, 2, or 3");                filename = (filename + ".txt");                //storing file array                //calculations                g.drawstring("" + compname, 330, 15);               //more drawstrings                 //action end-------------------------------------------             }          });         pcframe.setvisible( true );    } }); modepanel.add(pcbutton); 

when pcbutton pressed, user supposed enter name, file, etc. however, every dialog input shows twice. want inputs show once.

any appreciated, thanks.

sorry, that's wrong. should never call joptionpanes or other painting within paintcomponent method. never have full control on when or if method gets called, , program's perceived responsiveness partly dependent on how fast method completes jobs. main recommendation -- non-painting code out of method , method you can control.

myself, rather throw bunch of joptionpanes @ user, i'd create jpanel has fields want user fill out, , show 1 single joptionpane holds jpanel, , input @ once.

next, secondary dialog window should true dialog, , swing means jdialog (or joptionpane type of modal jdialog) , not jframe.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -