0
package einstein;
import javax.swing.JApplet; 
import java.awt.*;

启动小程序

public class Einstein extends JApplet 
{
//--------------------------------------------------------|
//draws a quotation from albert einstein among some shapes|
//--------------------------------------------------------|
@Override
public void paint (Graphics page)
{

下一行表达式的非法开头

    page.drawRect (50, 50, 40, 40,); //square
    page.drawRect (60, 80, 225, 30); //rectangle
    page.drawOval (75, 65, 20, 20); //circle
    page.drawLine (35, 60, 100, 120); //line

    page.drawString ("Out of clutter, find simplicity.", 110, 70);
    page.drawString ("-- Albert Einstein", 130, 100);

    }
}

它最初有油漆(图形页面)的问题,但显然@overide 解决了这个问题

4

2 回答 2

0

Ben 只需删除您在为 page.drawRect (50, 50, 40, 40,) 传递的第四个值之后输入的额外逗号;//删除逗号 :)

如果您想查看您的小程序,您的最终代码应该是这样的:

import javax.swing.JApplet; 
import java.awt.*;

public class Einstein extends JApplet 
{
//--------------------------------------------------------|
//draws a quotation from albert einstein among some shapes|
//--------------------------------------------------------|
@Override
public void paint (Graphics page)
{   
    page.drawRect (50, 50, 40, 40); //square
    page.drawRect (60, 80, 225, 30); //rectangle
    page.drawOval (75, 65, 20, 20); //circle
    page.drawLine (35, 60, 100, 120); //line

    page.drawString ("Out of clutter, find simplicity.", 110, 70);
    page.drawString ("-- Albert Einstein", 130, 100);

    }
}

/*<APPLET CODE="Einstein.java" HEIGHT = 400 WIDTH = 400></APPLET>*/
于 2013-08-06T08:24:01.667 回答
0
 page.drawRect (50, 50, 40, 40,); // remove extra , 

使用如下

page.drawRect (50, 50, 40, 40);     

这不是一个严肃的问题,下次来这里之前检查你的代码两次。另外我建议您使用 IDE 进行编码,因为它会指导您解决此类问题。

于 2013-08-06T08:24:02.080 回答