java - GWT - stockwatch example - event handling explanation -


first of all, hi everyone. i'm new here , have started learning gwt. there 1 thing dont understand regarding stockwatch example. first of all, there add stock method, adds new stock list. inside method add remove button , attach listener it. question is, how possible indexof attr set, when u dont enter part of code when u add new stock, u enter part when u click remove button. code works, , cant find explanation why..i tried debug app, still having trouble undestand. sorry bad english.

private void addstock() {     final string symbol = newsymboltextbox.gettext().touppercase().trim();      //validaciju vrsimo upotrebom regularnih izraza     if(symbol.matches("[0-9a-z]"))     {          window.alert("'" + symbol + "' not valid symbol.");          newsymboltextbox.selectall();          return;      }      newsymboltextbox.settext("");      if(stocks.contains(symbol))     {         return;     }      int row = stocksflextable.getrowcount();     stocks.add(symbol);     stocksflextable.settext(row, 0, symbol);     button removestockbutton = new button("x");      removestockbutton.addclickhandler(new clickhandler() {          @override         public void onclick(clickevent event) {             int indexof = stocks.indexof(symbol);             stocks.remove(indexof);             stocksflextable.removerow(indexof + 1);          }     });      stocksflextable.setwidget(row, 3, removestockbutton);      refreshwatchlist(); } 

my question is, how possible indexof attr set, when u dont enter part of code when u add new stock, u enter part when u click remove button.

read anonymous inner classes event listeners. new clickhandler() provides handler each button, catches click event, functionality remove line, whenever specific delete button pressed. every button has it's own clickhandler.

indexof not great name variable. rather stick removedindex, used in www.gwtproject.org sample code:

    // add button remove stock table.     button removestockbutton = new button("x");     removestockbutton.addclickhandler(new clickhandler() {         public void onclick(clickevent event) {             int removedindex = stocks.indexof(symbol);             stocks.remove(removedindex);             stocksflextable.removerow(removedindex + 1);         }     });     stocksflextable.setwidget(row, 3, removestockbutton); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -