java中的错误(GUI程序) [英] Error in java (GUI program)
问题描述
嘿伙计们请帮我解决我的代码无法正常工作并在我尝试点击计算按钮时显示错误
hey guys please help me with my code its not working and showing error when im trying to click the calculate button
String cp;
cp = a7.getText();
int d = Integer.parseInt(cp);
char m = cp.charAt(0); double p;
if (m=='A')
{a8.setText("gold");
p = d-(d*0.15);
a9.setText("discounted"+p);
}
if(m=='B')
{a8.setText("platinum");
p=d-(d*0.10);
a9.setText("discounted"+p);
}
if(m=='C')
{a8.setText("bronze");
p=d-(d*0.05);
a9.setText("discouted"+p);
}
编码中没有错误,但是当我点击我的计算按钮时没有任何反应,我收到此错误调试器控制台:
there is no error in the coding but when i click my calculate button nothing happens and i get this error in the debugger console:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "B"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at NewJFrame.jButton1ActionPerformed(NewJFrame.java:100)
at NewJFrame.access$000(NewJFrame.java:11)
at NewJFrame$1.actionPerformed(NewJFrame.java:45)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6539)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6304)
at java.awt.Container.processEvent(Container.java:2239)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
$ b $对不起,这是我第一次来这里。
但这里有一些截图我提供更好的信息
https://gyazo.com/d1209e7ed9493e657d8e596b5bc1eadd
所以你可以看到代码部分没有这样的错误,但我可能在某处错了,如果我请在其中纠正我。
https://gyazo.com/d1209e7ed9493e657d8e596b5bc1eadd
这里是另一个截图,所以当我点击计算时按钮后r把卡的类型应该在第三个文本字段显示黄金,白金等,但当我点击它没有任何反应,我得到错误,你可以在截图中看到
我尝试了什么:
我已经尝试了一切,但也许我认为会使用float吗? idk伙伴帮我解决
im sorry this is my first time on here.
but here are some screenshots im providing for better information
https://gyazo.com/d1209e7ed9493e657d8e596b5bc1eadd
so as you can see there are no such errors in the code part but i might be wrong somewhere and if i am please correct me in it.
https://gyazo.com/d1209e7ed9493e657d8e596b5bc1eadd
here is another screenshot, so when i click the calculate button after putting type of card it is supposed to show gold, platinum etc in the third textfield but when i click it nothing happens and i get the error as you can see in the screenshot
What I have tried:
ive tried everything but maybe i think float will be used instead? idk guys help me out
推荐答案
000(NewJFrame.java:11)
at NewJFrame
000(NewJFrame.java:11) at NewJFrame
1.actionPerformed (NewJFrame.java:45)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton
1.actionPerformed(NewJFrame.java:45) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton
Handler.actionPerformed (AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6539)
at javax.swing.JComponent.processMouseEvent( JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6304)
at java.awt.Container.processEvent(Container.java:2239)
at java .awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEven tImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java) :2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt。 EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access
Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6539) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6304) at java.awt.Container.processEvent(Container.java:2239) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2297) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476) at java.awt.Container.dispatchEventImpl(Container.java:2283) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) at java.awt.EventQueue.access
这篇关于java中的错误(GUI程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!