【发布时间】:2016-09-26 01:45:19
【问题描述】:
我正在使用 Blue Jay 并且只想创建一个简单的矩形。我尝试添加一个类来使用 Canvas 方法,但它似乎不起作用。我在所有开头的三行中都收到错误“预期的类、接口或枚举”,然后是另一个错误:
Canvas.java:1:错误:需要类、接口或枚举 java.lang.对象; ^ Canvas.java:2:错误:需要类、接口或枚举 java.awt.组件; ^ Canvas.java:3:错误:需要类、接口或枚举 java.awt.Canvas; ^ Canvas.java:18:错误:方法声明无效;需要返回类型 公开测试() ^ 4 个错误我的代码是:
java.lang.Object;
java.awt.Component;
java.awt.Canvas;
/**
* Write a description of class test here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Canvas
{
// instance variables - replace the example below with your own
private int x;
/**
* Constructor for objects of class test
*/
public test()
{
// initialize instance variables
//Going to insert the code right here
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public int sampleMethod(int y)
{
// put your code here
return x + y;
}
}
【问题讨论】:
-
还有一个作业问题?
-
那个无效的构造函数有什么用?为什么你的班级会影响 Java 的 Canvas?枚举和这个有什么关系?
-
@AndrewL.:嗯,
enum部分只是来自错误消息。 -
@T.J.Crowder 我看到了,但它根本没有直接关系
-
前三行应该做什么?