2011-03-31 89 views
1

我一直在爲這個學校的代碼工作,但我一直在得到一些錯誤,我不能fix.can有人幫助我!!!!。代碼所做的是用戶在文本框中輸入數字1 2 3或4,Applet將爲每個數字繪製不同的形狀。如何解決這些「非法表達式」錯誤?

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); 


} 

} 

} 

} 
+0

這不是如何在SO上提出問題,這就是爲什麼你的問題即將被關閉爲「不是真正的問題」。請閱讀http://stackoverflow.com/questions/how-to-ask。 – 2011-03-31 18:00:54

+0

這不是很具體,吉姆。我實際上認爲他很好地識別了他收到的錯誤,並標記了錯誤所在的代碼行號。當你關閉它時,我正在做一個很好的答案。太糟糕了,我無法幫助這個人。我正在提名重新開放。 – 2011-03-31 18:03:54

+1

如果你已經關閉它作爲這個問題的重複,我可能已經瞭解:http://stackoverflow.com/questions/1534263/how-doi-i-fix-an-illegal-start-of-expression-error-在Java的 – 2011-03-31 18:08:31

回答

1

爲什麼方法油漆定義裏面actionPeformed

0

您錯過了other.setforeground(Color.RED)之後的關閉;(並且您還在繪畫定義之前完成了此操作)。當你看到一個錯誤時,試着看看前面的幾行,因爲它會經常給你一個關於錯誤的提示。