我定义了一个文本区 JText text=new JText();
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==butn)
N=Integer.parseInt(text.getText());
p.setLayout(new GridLayout(N,N));
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
p.add(cell[i][j] = new Cell()); }
然后在文本区里输入整数,在文本区的一旁,定义了一个按钮,输入整数后,按按钮,
定义个一个变量N就得到了整数。但运行时有错误,怎么回事啊
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==butn)
N=Integer.parseInt(text.getText());
p.setLayout(new GridLayout(N,N));
for (int i=0; i<N; i++)
for (int j=0; j<N; j++)
p.add(cell[i][j] = new Cell()); }
然后在文本区里输入整数,在文本区的一旁,定义了一个按钮,输入整数后,按按钮,
定义个一个变量N就得到了整数。但运行时有错误,怎么回事啊
try{
N=Integer.parseInt(text.getText());
}catch(Exception e){}
at TicTacToe.actionPerformed(TicTacToe.java:52)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)好多异常啊
先确定下p是否为null
p是一个面板,前面定义的,这个程序编译没错,运行没错。运行时,我输入数值,按按钮,没反应。然后就有错了
p.setLayout(new GridLayout(N,N));