java - Where to put popup code -
so i'm making gui menu drop downs. wanted have gui create popup window whenever user selects option drop down menu. should put code popup within actionperformed method or make separate method , call somewhere else?
here code:
import java.awt.container; import java.awt.flowlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.japplet; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.jtextfield; public class finalgui2 extends japplet{ private jtextfield text = new jtextfield(10); private actionlistener listen = new actionlistener(){ public void actionperformed(actionevent e){ } }; private jmenu[] menu = {new jmenu("food"), new jmenu("fluid"), new jmenu("sleep")}; private jmenuitem[] items = {new jmenuitem("add"), new jmenuitem("add"), new jmenuitem("add"), new jmenuitem("edit"), new jmenuitem("edit"), new jmenuitem("edit"), new jmenuitem("delete"), new jmenuitem("delete"), new jmenuitem("delete")}; public void init(){ for(int = 0; < items.length; i++){ items[i].addactionlistener(listen); menu[i%3].add(items[i]); } jmenubar bar = new jmenubar(); for(int = 0; < menu.length; i++) bar.add(menu[i]); setjmenubar(bar); container contain = getcontentpane(); contain.setlayout(new flowlayout()); contain.add(text); } public static void main(string[] args){ run(new finalgui2(), 200, 75); } public static void run(japplet app, int width, int height){ jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().add(app); frame.setsize(width, height); app.init(); app.start(); frame.setvisible(true); }
}
in jmenuitem
's actionlistener
. maybe have @ how use menus, how write action listeners and/or how use actions more details
should put code popup within actionperformed method or make separate method , call somewhere else?
well, that's you. personally, re-usable code, using method or class preferred solution, come down own context , needs
Comments
Post a Comment