java - How to create a button and locate it on a panel based on user input -


in first frame, have panel form layout, have "add" button. when user click add button, second frame shown. second frame shown allow user fill information needed create button in a.java.

add button on frame of a.java:

jbutton button_3 = new jbutton("add");//add row     button_3.addactionlistener(new actionlistener() {          public void actionperformed(actionevent e) {             addcheckup addc = new addcheckup();//note addcheckup b.java             addc.setvisible(true);             addc.setdefaultcloseoperation(windowconstants.dispose_on_close);          }      }); 

frame of a.java:

enter image description here

if user click add button @ frame of a.java, frame of b.java shown.

frame of b.java:

enter image description here

after user finish in giving input @ frame of b.java, add button clicked. new button created @ frame of a.java based on user input @ frame of b.java.

so far, when add button @ frame of b.java clicked, information saved text file. below add button code.

jbutton btnadd = new jbutton("add");     btnadd.addactionlistener(new actionlistener() {         public void actionperformed(actionevent arg0) {              system.out.println(combobox_1.getselecteditem());   //getactivity               if (chckbxnewcheckbox.isselected()){//if complication                 system.out.println("*"+textfield.gettext());//settaskname have * sign                 }             else{                 system.out.println(textfield.gettext());                     }             system.out.println(combobox.getselecteditem());  //getday                string filename = "c:" + file.separator + "text file b.java class.txt";                 file f = new file(filename);                 printwriter pw = null;                 try {                      pw = new printwriter(f);                                     pw.println(combobox_1.getselecteditem());                     if (chckbxnewcheckbox.isselected()){//if complication                         pw.println("*"+textfield.gettext());                          }                     else{                         pw.println(textfield.gettext());                          }                     pw.println(combobox.getselecteditem());                     pw.flush();                  } catch (filenotfoundexception e) {                     e.printstacktrace();                 }finally{                      if(pw!=null){                         pw.close();                     }              }              joptionpane.showmessagedialog(null,"successfully added !");         }     });  

now, intend access text file , create new button based on information text file. don't know how make new button based on information text file. if there other method more easier, please let me know.

i want create button this: put @ b.java

jbutton btn_34 = new jbutton("uptitrate bb");//task name bigpanel.add(btn_34, "12, 11");  //12 , 11 based on activity , day 

but error in bigpanel.add

i use properties read , write this.

so need keys , values.

final properties prop = new properties(); prop.setproperty("activity", combobox_1.getselecteditem()); prop.setproperty("complication", chckbxnewcheckbox.isselected()); prop.setproperty("day", combobox.getselecteditem()); writepropertyintofile("c:" + file.separator + "text file b.java   class.txt", prop); 

and write method may this

private static void writepropertyintofile(string file, final properties prop)         throws filenotfoundexception, ioexception {     try (final fileoutputstream f = new fileoutputstream(file);) {         prop.store(f, null);     } } 

sincerely

update-1

i assume have property file containing

b1.day,1 b1.complication,true b1.activity,diagnose b2.day,2 b2.complication,false b2.activity,labs b3.day,5 b3.complication,false b3.activity,oxygon 

now, need loop on bs call createbutton each containing in property file. may save last used index. if user adds new one. create new button bn. save in file , done.

update-2

jbutton button_3 = new jbutton("add");//add row button_3.addactionlistener(new actionlistener() {      public void actionperformed(actionevent e) {         string btname = getnextfreebuttonname();         button btnx = createnewbutton("oxy", "11","10", btname);         mapcontainingallbuttons.put(btname, btnx)         addbuttontofram(btnx);     } }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -