swing - Java GUI Blank and nullpointerexception -
i fixed when click on calculate button following:
this working except calculate button now, , important part. thank in advance help.
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ radio$calcbuttonlistener.actionperformed(radio.java:76) @ javax.swing.abstractbutton.fireactionperformed(unknown source) @ javax.swing.abstractbutton$handler.actionperformed(unknown source) @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @ javax.swing.defaultbuttonmodel.setpressed(unknown source) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source) import java.awt.*; import java.awt.event.*; import javax.swing.*; public class radio extends jframe { private jpanel panel; private jpanel buttonpanel; private jtextfield base; private jtextfield width; private jradiobutton squarearea; private jradiobutton parallelogramarea; private final int window_width = 550; private final int window_height = 550; double ptotal; double stotal; public radio() { setsize(window_width, window_height); settitle("area calculator"); setdefaultcloseoperation(jframe.exit_on_close); setvisible(true); buildpanel(); add(panel); } private void buildpanel() { panel = new jpanel(); jlabel messagelabel1 = new jlabel("please enter base: "); jtextfield base = new jtextfield(10); jlabel messagelabel2 = new jlabel("please enter width: "); jtextfield width = new jtextfield(10); jradiobutton squarearea = new jradiobutton("choice 1", true); jradiobutton parallelogramarea = new jradiobutton("choice 2"); buttongroup group = new buttongroup(); jbutton calcbutton = new jbutton("calculate"); calcbutton.setbackground(color.blue); calcbutton.setforeground(color.pink); calcbutton.addactionlistener(new calcbuttonlistener()); panel.add(messagelabel1); panel.add(base); panel.add(messagelabel2); panel.add(width); group.add(squarearea); group.add(parallelogramarea); panel.add(squarearea); panel.add(parallelogramarea); panel.add(calcbutton); } public static void main (string[] args) { radio radio = new radio(); radio.buildpanel(); } private class calcbuttonlistener implements actionlistener { public void actionperformed(actionevent e) { if (parallelogramarea.isselected()); { ptotal = double.parsedouble(base.gettext()) * double.parsedouble(width.gettext()); joptionpane.showmessagedialog(null, "the area is: " + ptotal); } if (squarearea.isselected()) { stotal = double.parsedouble(base.gettext()) * double.parsedouble(width.gettext()); joptionpane.showmessagedialog(null, "the area is: " + stotal); } } } }
i think buttonpanel
null. can debug code line - by-line figure out of them null
Comments
Post a Comment