JavaFXの参考書でEclipseを使って勉強しています。実行するとmainメソッドがありません。と出て実行できないのですが、このコードにmainメソッドをつけ方がわからないので教えていただけませんか。
エラー画面は
Java Virtual Machine Launcher
error: Could not create the Java Virtual Machine.
error: A fatal exception has occurred.Program will exit.
と出ています。
// LineClass.java package topic01; import java.util.ArrayList; import java.util.List; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.stage.Stage; class Line { double lineWidth; // フィールド宣言 double ypos; Color lineColor; public Line() // コンストラクタ { this(1.0,20,Color.BLACK); } public Line(double y) { this(1.0, y, Color.BLACK); } public Line(double y, Color col) { this(1.0, y, col); } public Line(double linewidth, double y, Color col) { lineWidth = linewidth; ypos = y; lineColor = col; } // 線を描く public void drawLine(GraphicsContext gc) { gc.setLineWidth(lineWidth); gc.setStroke(lineColor); gc.strokeLine(10, ypos, 230, ypos); } } public class LineClass extends Application { @Override public void start(Stage stage) throws Exception { stage.setTitle("LineClass"); stage.setWidth(260); stage.setHeight(110); Group root = new Group(); final Canvas canvas = new Canvas(250,250); GraphicsContext gc = canvas.getGraphicsContext2D(); // 線を作成する List <Line> lines = new ArrayList<Line>(); lines.add(new Line()); lines.add(new Line(30.0)); lines.add(new Line(40.0, Color.BLUE)); lines.add(new Line(2.0, 50.0, Color.ROSYBROWN)); // 線を描く for(Line line : lines) line.drawLine(gc); root.getChildren().add(canvas); stage.setScene(new Scene(root, 300, 300)); stage.show(); } }
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/06/07 05:35
2019/06/07 05:38
2019/06/07 05:44
退会済みユーザー
2019/06/07 05:46
2019/06/07 05:47
退会済みユーザー
2019/06/07 05:55
2019/06/07 06:04
退会済みユーザー
2019/06/07 06:15
2019/06/07 06:23
退会済みユーザー
2019/06/07 06:42
退会済みユーザー
2019/06/07 06:43
2019/06/08 13:16
退会済みユーザー
2019/06/09 01:08
2019/06/10 02:35
2019/06/10 03:26