ブルージェイを使用していて、単純な矩形を作成したいとします。私はCanvasメソッドを使うクラスを追加しようとしましたが、うまくいかないようです。ブルージェイの「クラス、インターフェイス、または列挙型の予想」エラーが発生しています
Canvas.java:1: error: class, interface, or enum expected java.lang.Object; ^ Canvas.java:2: error: class, interface, or enum expected java.awt.Component; ^ Canvas.java:3: error: class, interface, or enum expected java.awt.Canvas; ^ Canvas.java:18: error: invalid method declaration; return type required public test() ^ 4 errors
私のコードは次のとおりです:
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をシャドーしていますか?列挙型はこれと何が関係していますか? – Li357
@AndrewL .:まあ、 'enum'の部分はエラーメッセージのものです。 –