java - How I remove inputted numbers from a Text Area? -


/*  * integersumsview.java  * program allows individual add list of numbers, , choose whether   * add numbers, or or odd numbers  */     public class integersumsview extends frameview {  //  int position = 0; int[] aryinteger = new int[10];   public integersumsview(singleframeapplication app) {     super(app);      initcomponents();      // status bar initialization - message timeout, idle icon , busy animation, etc     resourcemap resourcemap = getresourcemap();     int messagetimeout = resourcemap.getinteger("statusbar.messagetimeout");     messagetimer = new timer(messagetimeout, new actionlistener() {         public void actionperformed(actionevent e) {             statusmessagelabel.settext("");         }     });     messagetimer.setrepeats(false);     int busyanimationrate = resourcemap.getinteger("statusbar.busyanimationrate");     (int = 0; < busyicons.length; i++) {         busyicons[i] = resourcemap.geticon("statusbar.busyicons[" + + "]");     }     busyicontimer = new timer(busyanimationrate, new actionlistener() {         public void actionperformed(actionevent e) {             busyiconindex = (busyiconindex + 1) % busyicons.length;             statusanimationlabel.seticon(busyicons[busyiconindex]);         }     });     idleicon = resourcemap.geticon("statusbar.idleicon");     statusanimationlabel.seticon(idleicon);     progressbar.setvisible(false);      // connecting action tasks status bar via taskmonitor     taskmonitor taskmonitor = new taskmonitor(getapplication().getcontext());     taskmonitor.addpropertychangelistener(new java.beans.propertychangelistener() {         public void propertychange(java.beans.propertychangeevent evt) {             string propertyname = evt.getpropertyname();             if ("started".equals(propertyname)) {                 if (!busyicontimer.isrunning()) {                     statusanimationlabel.seticon(busyicons[0]);                     busyiconindex = 0;                     busyicontimer.start();                 }                 progressbar.setvisible(true);                 progressbar.setindeterminate(true);             } else if ("done".equals(propertyname)) {                 busyicontimer.stop();                 statusanimationlabel.seticon(idleicon);                 progressbar.setvisible(false);                 progressbar.setvalue(0);             } else if ("message".equals(propertyname)) {                 string text = (string)(evt.getnewvalue());                 statusmessagelabel.settext((text == null) ? "" : text);                 messagetimer.restart();             } else if ("progress".equals(propertyname)) {                 int value = (integer)(evt.getnewvalue());                 progressbar.setvisible(true);                 progressbar.setindeterminate(false);                 progressbar.setvalue(value);             }         }     }); }  @action public void showaboutbox() {     if (aboutbox == null) {         jframe mainframe = integersumsapp.getapplication().getmainframe();         aboutbox = new integersumsaboutbox(mainframe);         aboutbox.setlocationrelativeto(mainframe);     }     integersumsapp.getapplication().show(aboutbox); }  /** method called within constructor  * initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() {      mainpanel = new javax.swing.jpanel();     integerlabel = new javax.swing.jlabel();     enterintfield = new javax.swing.jtextfield();     addintbutton = new javax.swing.jbutton();     sumallbutton = new javax.swing.jbutton();     useroutputfield = new javax.swing.jtextfield();     sumevenbutton = new javax.swing.jbutton();     jscrollpane1 = new javax.swing.jscrollpane();     useroutputarea = new javax.swing.jtextarea();     sumoddbutton = new javax.swing.jbutton();     removeintbutton = new javax.swing.jbutton();     menubar = new javax.swing.jmenubar();     javax.swing.jmenu filemenu = new javax.swing.jmenu();     javax.swing.jmenuitem exitmenuitem = new javax.swing.jmenuitem();     javax.swing.jmenu helpmenu = new javax.swing.jmenu();     javax.swing.jmenuitem aboutmenuitem = new javax.swing.jmenuitem();     statuspanel = new javax.swing.jpanel();     javax.swing.jseparator statuspanelseparator = new javax.swing.jseparator();     statusmessagelabel = new javax.swing.jlabel();     statusanimationlabel = new javax.swing.jlabel();     progressbar = new javax.swing.jprogressbar();      org.jdesktop.application.resourcemap resourcemap = org.jdesktop.application.application.getinstance(integersums.integersumsapp.class).getcontext().getresourcemap(integersumsview.class);     integerlabel.settext(resourcemap.getstring("integerlabel.text")); // noi18n     integerlabel.setname("integerlabel"); // noi18n      enterintfield.settext(resourcemap.getstring("enterintfield.text")); // noi18n     enterintfield.setname("enterintfield"); // noi18n      addintbutton.settext(resourcemap.getstring("addintbutton.text")); // noi18n     addintbutton.setname("addintbutton"); // noi18n     addintbutton.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             addintbuttonactionperformed(evt);         }     });      sumallbutton.settext(resourcemap.getstring("sumallbutton.text")); // noi18n     sumallbutton.setname("sumallbutton"); // noi18n     sumallbutton.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             sumallbuttonactionperformed(evt);         }     });      useroutputfield.settext(resourcemap.getstring("useroutputfield.text")); // noi18n     useroutputfield.setname("useroutputfield"); // noi18n      sumevenbutton.settext(resourcemap.getstring("sumevenbutton.text")); // noi18n     sumevenbutton.setname("sumevenbutton"); // noi18n     sumevenbutton.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             sumevenbuttonactionperformed(evt);         }     });      jscrollpane1.setname("jscrollpane1"); // noi18n      useroutputarea.setcolumns(20);     useroutputarea.setrows(5);     useroutputarea.setname("useroutputarea"); // noi18n     jscrollpane1.setviewportview(useroutputarea);      sumoddbutton.settext(resourcemap.getstring("sumoddbutton.text")); // noi18n     sumoddbutton.setname("sumoddbutton"); // noi18n     sumoddbutton.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             sumoddbuttonactionperformed(evt);         }     });      removeintbutton.settext(resourcemap.getstring("removeintbutton.text")); // noi18n     removeintbutton.setname("removeintbutton"); // noi18n     removeintbutton.addactionlistener(new java.awt.event.actionlistener() {         public void actionperformed(java.awt.event.actionevent evt) {             removeintbuttonactionperformed(evt);         }     });      javax.swing.grouplayout mainpanellayout = new javax.swing.grouplayout(mainpanel);     mainpanel.setlayout(mainpanellayout);     mainpanellayout.sethorizontalgroup(         mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(mainpanellayout.createsequentialgroup()             .addcontainergap()             .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                 .addcomponent(useroutputfield, javax.swing.grouplayout.default_size, 372, short.max_value)                 .addgroup(mainpanellayout.createsequentialgroup()                     .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                         .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                             .addgroup(javax.swing.grouplayout.alignment.trailing, mainpanellayout.createsequentialgroup()                                 .addcomponent(addintbutton)                                 .addgap(89, 89, 89))                             .addgroup(mainpanellayout.createsequentialgroup()                                 .addcomponent(sumallbutton)                                 .addgap(73, 73, 73))                             .addgroup(mainpanellayout.createsequentialgroup()                                 .addcomponent(sumevenbutton)                                 .addgap(61, 61, 61))                             .addgroup(mainpanellayout.createsequentialgroup()                                 .addcomponent(sumoddbutton)                                 .addgap(65, 65, 65)))                         .addgroup(mainpanellayout.createsequentialgroup()                             .addcomponent(integerlabel)                             .addgap(18, 18, 18)                             .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                                 .addcomponent(removeintbutton)                                 .addcomponent(enterintfield, javax.swing.grouplayout.preferred_size, 30, javax.swing.grouplayout.preferred_size))))                     .addgap(18, 18, 18)                     .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 181, javax.swing.grouplayout.preferred_size)))             .addgap(18, 18, 18))     );     mainpanellayout.setverticalgroup(         mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(mainpanellayout.createsequentialgroup()             .addgap(48, 48, 48)             .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.trailing)                 .addgroup(mainpanellayout.createsequentialgroup()                     .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                         .addcomponent(integerlabel)                         .addcomponent(enterintfield, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))                     .addgroup(mainpanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)                         .addgroup(mainpanellayout.createsequentialgroup()                             .addgap(36, 36, 36)                             .addcomponent(removeintbutton))                         .addgroup(mainpanellayout.createsequentialgroup()                             .addgap(18, 18, 18)                             .addcomponent(addintbutton)                             .addgap(8, 8, 8)                             .addcomponent(sumallbutton)                             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                             .addcomponent(sumevenbutton)                             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)                             .addcomponent(sumoddbutton)))                     .addgap(19, 19, 19))                 .addgroup(mainpanellayout.createsequentialgroup()                     .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 151, javax.swing.grouplayout.preferred_size)                     .addgap(18, 18, 18)))             .addcomponent(useroutputfield, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)             .addcontainergap(17, short.max_value))     );      menubar.setname("menubar"); // noi18n      filemenu.settext(resourcemap.getstring("filemenu.text")); // noi18n     filemenu.setname("filemenu"); // noi18n      javax.swing.actionmap actionmap = org.jdesktop.application.application.getinstance(integersums.integersumsapp.class).getcontext().getactionmap(integersumsview.class, this);     exitmenuitem.setaction(actionmap.get("quit")); // noi18n     exitmenuitem.setname("exitmenuitem"); // noi18n     filemenu.add(exitmenuitem);      menubar.add(filemenu);      helpmenu.settext(resourcemap.getstring("helpmenu.text")); // noi18n     helpmenu.setname("helpmenu"); // noi18n      aboutmenuitem.setaction(actionmap.get("showaboutbox")); // noi18n     aboutmenuitem.setname("aboutmenuitem"); // noi18n     helpmenu.add(aboutmenuitem);      menubar.add(helpmenu);      statuspanel.setname("statuspanel"); // noi18n      statuspanelseparator.setname("statuspanelseparator"); // noi18n      statusmessagelabel.setname("statusmessagelabel"); // noi18n      statusanimationlabel.sethorizontalalignment(javax.swing.swingconstants.left);     statusanimationlabel.setname("statusanimationlabel"); // noi18n      progressbar.setname("progressbar"); // noi18n      javax.swing.grouplayout statuspanellayout = new javax.swing.grouplayout(statuspanel);     statuspanel.setlayout(statuspanellayout);     statuspanellayout.sethorizontalgroup(         statuspanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addcomponent(statuspanelseparator, javax.swing.grouplayout.default_size, 400, short.max_value)         .addgroup(statuspanellayout.createsequentialgroup()             .addcontainergap()             .addcomponent(statusmessagelabel)             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 230, short.max_value)             .addcomponent(progressbar, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)             .addcomponent(statusanimationlabel)             .addcontainergap())     );     statuspanellayout.setverticalgroup(         statuspanellayout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addgroup(statuspanellayout.createsequentialgroup()             .addcomponent(statuspanelseparator, javax.swing.grouplayout.preferred_size, 2, javax.swing.grouplayout.preferred_size)             .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, javax.swing.grouplayout.default_size, short.max_value)             .addgroup(statuspanellayout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)                 .addcomponent(statusmessagelabel)                 .addcomponent(statusanimationlabel)                 .addcomponent(progressbar, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))             .addgap(3, 3, 3))     );      setcomponent(mainpanel);     setmenubar(menubar);     setstatusbar(statuspanel); }// </editor-fold>  private void addintbuttonactionperformed(java.awt.event.actionevent evt) {                                                   //i apologize if these comments little imformal...or doesn't quite make sense, i'm new @     //here, add integer enterintfield, , after pressing addintbutton, integer inputted     //useroutputarea,      //the "null" when go add second integer, not input both first integer again ( second integer)     //you can add 10 different variables.     //now apologize if of terminology wrong...or makes no sense      aryinteger[position] = integer.parseint(enterintfield.gettext());     position ++;      useroutputarea.settext(null);      (int = 0; < position; i++) {         useroutputarea.settext(useroutputarea.gettext() + aryinteger[i] + "\n");      }  }                                              private void sumallbuttonactionperformed(java.awt.event.actionevent evt) {                                                   //this adds numbers inputted , outputs useroutputfield...      int sumall = 0;      for(int = 0; < position; i++)     {     sumall += aryinteger[i];     }      useroutputfield.settext("the sum of numbers " + sumall);  }                                              private void sumevenbuttonactionperformed(java.awt.event.actionevent evt) {                                                    //add numbers      int sumeven = 0;      for(int = 0; < position; i++)     {         if(aryinteger[i]%2==0) {         sumeven += aryinteger[i];         }     }     useroutputfield.settext("the sum of numbers " + sumeven);  }                                               private void sumoddbuttonactionperformed(java.awt.event.actionevent evt) {                                                   //adds odd numbers...      int sumodd = 0;      for(int = 0; < position; i++)     {         if(aryinteger[i]%2!=0) {         sumodd += aryinteger[i];         }     }     useroutputfield.settext("the sum of odd numbers " + sumodd);  }                                             

the problem below...

private void removeintbuttonactionperformed(java.awt.event.actionevent evt) {                                                 

and here create 'remove' button takes out integers inputted in useroutputarea. user can start scratch without having exit program , reopen it.

i thought "i" because that's variable/letter used add integers below 'addintbuttonactionperformed' ...but again perhaps "i" underlined because there no mention of under public class? add there without messing else up? makes sense me, however...this fifth program i've ever made in java may think has high chance of being horribly wrong. know pathetic, honest best attempt @ moment, i'm still attempting while wait replies. small hint appreciated!

    aryinteger.remove(i);  }                                                // 3 5 6 8 9 // variables declaration - not modify private javax.swing.jbutton addintbutton; private javax.swing.jtextfield enterintfield; private javax.swing.jlabel integerlabel; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jpanel mainpanel; private javax.swing.jmenubar menubar; private javax.swing.jprogressbar progressbar; private javax.swing.jbutton removeintbutton; private javax.swing.jlabel statusanimationlabel; private javax.swing.jlabel statusmessagelabel; private javax.swing.jpanel statuspanel; private javax.swing.jbutton sumallbutton; private javax.swing.jbutton sumevenbutton; private javax.swing.jbutton sumoddbutton; private javax.swing.jtextarea useroutputarea; private javax.swing.jtextfield useroutputfield; // end of variables declaration 

it seems want clear out jtextarea type component useroutputarea. if got right, line of code should it:

useroutputarea.settext(""); 

if meant else, please clarify task further.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -