NetBeans で単純な 2 人用の三目並べを作ろうとしていました。
6 つのテキスト フィールド、1 つの「パス」ボタン、1 つの「新しいゲーム」ボタン、および 1 つの終了ボタンを作成しました。
「合格」ボタンは、コード内ですべての力を持っています。ゲームの X と O の代わりに、X の場合は 1、O の場合は 2 など、任意の 2 つの整数を使用しています。
「パス」ボタンのコードは次のとおりです。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int a,b,c,d,e,f,g,h,i;
a=Integer.parseInt((jTextField1.getText()).trim());
b=Integer.parseInt((jTextField2.getText()).trim());
c=Integer.parseInt((jTextField3.getText()).trim());
d=Integer.parseInt((jTextField4.getText()).trim());
e=Integer.parseInt((jTextField5.getText()).trim());
f=Integer.parseInt((jTextField6.getText()).trim());
g=Integer.parseInt((jTextField7.getText()).trim());
h=Integer.parseInt((jTextField8.getText()).trim());
i=Integer.parseInt((jTextField9.getText()).trim());
if
(
// if the grid is empty
((((jTextField1.getText()).trim()).isEmpty())== true)
&& ((((jTextField2.getText()).trim()).isEmpty())== true)
&& ((((jTextField3.getText()).trim()).isEmpty())== true)
&& ((((jTextField4.getText()).trim()).isEmpty())== true)
&& ((((jTextField5.getText()).trim()).isEmpty())== true)
&& ((((jTextField6.getText()).trim()).isEmpty())== true)
&& ((((jTextField7.getText()).trim()).isEmpty())== true)
&& ((((jTextField8.getText()).trim()).isEmpty())== true)
&& ((((jTextField9.getText()).trim()).isEmpty())== true)
)
{
jLabel1.setText("Let's Begin!");
}
else if // if it isn't empty
( //if partially full
((((jTextField1.getText()).trim()).isEmpty())== true)
|| ((((jTextField2.getText()).trim()).isEmpty())== true)
|| ((((jTextField3.getText()).trim()).isEmpty())== true)
|| ((((jTextField4.getText()).trim()).isEmpty())== true)
|| ((((jTextField5.getText()).trim()).isEmpty())== true)
|| ((((jTextField6.getText()).trim()).isEmpty())== true)
|| ((((jTextField7.getText()).trim()).isEmpty())== true)
|| ((((jTextField8.getText()).trim()).isEmpty())== true)
|| ((((jTextField9.getText()).trim()).isEmpty())== true)
)
{
if
(
((a==b)&&(b==c))
||((d==e)&&(e==f))
||((g==h)&&(h==i))
||((a==d)&&(d==g))
||((b==e)&&(d==h))
||((c==f)&&(f==i))
||((a==e)&&(e==f))
||((c==e)&&(e==g))
)
{
jLabel1.setText("We have a winner!");
}
else
{
jLabel1.setText("Okay, Next Move!");
}
}
else if
//it is completely full
(
((((jTextField1.getText()).trim()).isEmpty())== false)
&& ((((jTextField2.getText()).trim()).isEmpty())== false)
&& ((((jTextField3.getText()).trim()).isEmpty())== false)
&& ((((jTextField4.getText()).trim()).isEmpty())== false)
&& ((((jTextField5.getText()).trim()).isEmpty())== false)
&& ((((jTextField6.getText()).trim()).isEmpty())== false)
&& ((((jTextField7.getText()).trim()).isEmpty())== false)
&& ((((jTextField8.getText()).trim()).isEmpty())== false)
&& ((((jTextField9.getText()).trim()).isEmpty())== false)
)
{
if
(
((a==b)&&(b==c))
||((d==e)&&(e==f))
||((g==h)&&(h==i))
||((a==d)&&(d==g))
||((b==e)&&(d==h))
||((c==f)&&(f==i))
||((a==e)&&(e==f))
||((c==e)&&(e==g))
)
{
jLabel1.setText("We have a winner!");
}
else
{
jLabel1.setText("Nobody wins. :(");
}
}
}
これがおかしいと思ったら教えてください!私はただのアマチュアです。
ここに私が得るエラーがあります、
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
at projet.pys.TEST.jButton1ActionPerformed(TEST.java:181)
at projet.pys.TEST.access$000(TEST.java:11)
at projet.pys.TEST$1.actionPerformed(TEST.java:50)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
上記のすべてをご確認いただき、ご協力いただければ幸いです。