java - JOptionPane not showing up (null parameter, called from inner class) -
i new java, trying make simple application , there no way can joptionpane
show correctly , guess missing something:
here's code:
import java.awt.color; import java.awt.window; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.jframe; import javax.swing.jmenu; import javax.swing.jmenubar; import javax.swing.jmenuitem; import javax.swing.joptionpane; import javax.swing.jpanel; public class frame extends jframe { private static final long serialversionuid = 1l; final static int width = 400; final static int height = 400; public frame() { super("convert dxf alpha ver. - survey apps 2014"); setdefaultcloseoperation(exit_on_close); setsize(width, height); setresizable(false); setlocation(100, 100); setbackground(color.white); setvisible(true); welcomepanel welcomepanel = new welcomepanel(this); add(welcomepanel); } public void createmenupanel() { menupanel menu = new menupanel(); setjmenubar(menu.createmenu(this)); } } class menupanel extends jpanel implements actionlistener { private jmenuitem open,save,close; private jmenu file,about; private frame frame; private static final long serialversionuid = 1l; public jmenubar createmenu(frame frame) { this.frame = frame; jmenubar menubar = new jmenubar(); file = new jmenu("file"); = new jmenu("about"); menubar.add(file); menubar.add(about); open = new jmenuitem("open"); save = new jmenuitem("save"); close = new jmenuitem("close"); file.add(open); file.add(save); file.addseparator(); file.add(close); open.addactionlistener(this); save.addactionlistener(this); close.addactionlistener(this); about.addactionlistener(this); return menubar; } public menupanel() { setvisible(true); setopaque(true); setbackground(color.white); setsize(window.width,window.height); } @override public void actionperformed(actionevent e) { object source = e.getsource(); if(source == open) { frame.dispose(); } if(source == save) { } if(source == close) { } if(source == about) { joptionpane.showmessagedialog(frame, "easydxfcreator - alpha version"); } } }
(i skipped welcomeframe because it's welcome screen disappears after mouse click)
jmenu not operate in way. jmenu events need implement menulistener instead of actionlistener. actionlistener jmenuitem.
hope helps.
Comments
Post a Comment