Java 如何解决这些问题;“表达式开头非法”;错误?
我一直在为学校编写此代码,但我遇到了一些无法修复的错误。有人能帮我吗!!!!。代码的作用是用户在文本框中输入数字1、2、3或4,小程序将为每个数字绘制不同的形状Java 如何解决这些问题;“表达式开头非法”;错误?,java,Java,我一直在为学校编写此代码,但我遇到了一些无法修复的错误。有人能帮我吗!!!!。代码的作用是用户在文本框中输入数字1、2、3或4,小程序将为每个数字绘制不同的形状 the errors illegal start of expression - line 53 illegal start of expression - line 53 ';' expected - 53 ';' expected - 53 illegal start of expression - line 63 illegal
the errors
illegal start of expression - line 53
illegal start of expression - line 53
';' expected - 53
';' expected - 53
illegal start of expression - line 63
illegal start of expression - line 63
';' expected - 63
';' expected - 63
/**
* @(#)fourshapesACON.java
*
* fourshapesACON Applet application
*
* @
* @version 1.00 2011/3/28
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class fourshapesACON extends Applet
{
Container pane = getContentPane();
JLabel question = new JLabel("pick one of the four shapes:1-Cirle, 2-Square, 3-Rectangle, 4-Oval");
JLabel choice1 = new JLabel("Circle");
JLabel choice2 = new JLabel("Square");
JLabel choice3 = new JLabel("Rectangle");
JLabel choice4 = new JLabel("Oval");
JLabel other = new JLabel("the number you have pick didn't match. pick from the numbers given");
JTextField answer = new JTextField(20);
JButton hey = new JButton(Enter);
public void init()
{
pane.setLayout(new FlowLayout());
pane.add(question);
pane.add(choice1);
pane.add(choice2);
pane.add(choice3);
pane.add(choice4);
pane.add(other);
pane.add(anwser);
pane.add(hey);
pane.add(Enter);
hey.addActionListener(this);
pane.setBackground(Color.BLUE);
question.setforeground(Color.WHITE);
choice1.setforeground(Color.GREEN);
choice2.setforeground(Color.GREEN);
choice3.setforeground(Color.GREEN);
choice4.setforeground(Color.GREEN);
other.setforeground(Color.RED);
public void actionPeformed(ActionEvent e)***(this is line 53)***
{
String reply = answer.getText();
String choice1="1";
String choice2="2";
String choice3="3";
String choice4="4";
public void paint(Graphics g)***(this is line 63)***
{
if (reply.equals(choice1)) {
pane.add(choice1);
g.drawRoundRect(200,200,80,80);
} else if (reply.equals(choice2)){
pane.add(choice2);
g.drawfillRect(200,200,80,80);
} else if(reply.equals(choice3)) {
pane.add(choice3);
g.drawfillRect(200,200,80,40);
} else if (reply.equals(choice4)){
pane.add(choice4);
g.drawfillOval(200,200,50,50);
} else
pane.add(other);
}
}
}
}
为什么方法画图是在动作表中定义的?您错过了一个结束
在other.setforeground(Color.RED)
之后(在定义paint之前也做过此操作)。当你看到一个错误时,也试着看前面几行,因为这通常会给你一个错误的提示。这不是一个这样问问题的方式,这就是为什么你的问题将以“不是真正的问题”结束的原因。请看。这不是很具体,吉姆。事实上,我认为他在识别收到的错误和标记错误所在的代码行号方面做得很好。当你关闭它的时候,我正在寻找一个很好的答案。真可惜我帮不了这家伙。我正在提名重新开放。如果你把它作为这个问题的副本关闭,我可能会理解: