为什么我继续得到“ ')'预期'错误?
问题描述:
我已经加倍,三次检查我的开启和关闭括号。
每次我尝试编译我的代码时都会弹出以下错误:
C:\ Java 1 \新文件夹(3)\ Chapter05 /\\ Checkboard.java:82:')'预计
}
^
我的尝试:
I've double, triple checked my opening and closing braces.
Each time I try to compile my code the following error pops up:
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:82: ')' expected
}
^
What I have tried:
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class Checkerboard extends Frame implements ActionListener
{
Panel boardPanel = new Panel();
TextField textArray[] = new TextField[16];
Panel inputPanel = new Panel();
Label startLabel = new Label("Start");
Field startField = new TextField(2);
Label stopLabel = new Label("Stop");
Field stopField = new TextField(2);
Label stepLabel = new Label("Step");
Field stepField = new TextField(2);
Panel buttonPanel = new Panel();
Button goButton = new Button("Go");
Button clearButton = new Button("Clear");
int start = 0;
int stop = 0;
int step = 0;
public Checkerboard()
{
for(int i=0; i<textArray.lenth; i++)
{
textArray[i] = new TextField();
textArray[i].setEditable(false);
textArray[i].setText(String.valueOf(i));
textarray[i].setBackground(Color.white);
}
this.setLayout(new BorderLayout(2,2));
boardPanel.setLayout(new GridLayout(4,4,20,20));
inputPanel.setLayout(new GridLayout(2,3,20,20));
buttonPanel.setLayout(new GridLayout(1,2,5,5));
for(int j=0; j<textArray.length; j++)
boardPanel.add(textArray[j]);
inputPanel.add(startField);
inputPanel.add(stopField);
inputPanel.add(stepField);
inputPanel.add(startLabel);
inputPanel.add(stopLabel);
inputPanel.add(steplabel);
buttonPanel.add(goButton);
buttonPanel.add(clearButton);
add(inputPanel, BorderLayout.CENTER);
add(inputPanel, BorderLayout.NORTH);
add(inputPanel, BorderLayout.SOUTH);
startField.addActionListener(this);
stopField.addActionListener(this);
stepField.addActionListener(this);
goButton.addActionListener(this);
clearButton.addActionListener(this);
setVisible(true);
startField.requestFocus();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.ext(0);
}
}
} //LOCATION OF THE ERROR.
public void actionPerformed(ActionEvent e)
{
string arg = e.getActionCommand();
try
{
if(args == "Go")
{
int start = Integer.parseInt(startField.getText());
int step = Integer.parseInt(stepField.getText());
int stop = Integer.parseInt(stopField.getText());
for(int i=0; i<textArray.length; i++)
textArray[i].setBackgorund(Color.blue);
for(int i = start; i<textArray.length; i+=step)
textArray[i].setBackground(Color.yellow);
}
}
catch(Exception x)
{
JOptionPane.showMessageDialog(null,"Date Entry Error", "Error", JOptionPane.INFORMATION_MESSAGE);
args = "Clear";
}
if(args == "Clear")
{
startField.setText("");
stopField.setText("");
stepField.settext("");
for(int i=0; i<textArray.length; i++)
textArray[i].setBackground(Color.white);
}
}
public static void main(String[] args)
{
Checkerboard f = new Checkerboard();
f.setBounds(50,100,300,400);
f.setTitle("Checkerboard Array");
f.setVisible(true);
}
}
答
你错过了一个右括号和分号。
You're missing a closing parenthesis and semicolon.
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.ext(0);
}
});
这一行可能是罪魁祸首
This line may be culprit
addWindowListener(new WindowAdapter()
它打开2' ('并且只关闭1')'
可以猜测编译器会求失踪的。
it opens 2 '(' and close only 1 ')'
One can guess the compiler beg for the missing one.