Question: JAVA Receiving Error: Unable to initialize main class Painter Caused by: java.lang.NoClassDefFoundError: Stage //painterjava///////////////// import paintSlider.PainterController; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import

JAVA Receiving Error: Unable to initialize main class Painter Caused by: java.lang.NoClassDefFoundError: Stage

//painterjava/////////////////

import paintSlider.PainterController;

import javafx.application.Application;

import javafx.fxml.FXMLLoader;

import javafx.scene.Parent;

import javafx.scene.Scene;

import javafx.stage.Stage;

public class Painter extends Application {

@Override

public void start(Stage stage) throws Exception {

Parent root = FXMLLoader.load(getClass().getResource("Painter.fxml"));

Scene scene = new Scene(root);

stage.setTitle("Painter"); // displayed in window's title bar

stage.setScene(scene);

stage.show();

}

public static void main(String[] args) {

launch(args);

}

}

}

//PainterController////////////////

import paintSlider.PainterController;

import java.beans.value.ChangeListener;

import java.beans.value.ObservableValue;

import java.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.scene.control.RadioButton;

import javafx.scene.control.Slider;

import javafx.scene.control.ToggleGroup;

import javafx.scene.input.MouseEvent;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.paint.Paint;

import javafx.scene.shape.Circle;

import javafx.scence.shape.Rectangle;

public class PainterController {

private enum PenSize {

SMALL(2),

MEDIUM(4),

LARGE(6);

private final int radius;

PenSize(int radius) {

this.radius = radius;

}

public int getRadius() {

return radius;

}

};

// instance variables that refer to GUI components

@FXML private Slider redSlider;

@FXML private Slider greenSlider;

@FXML private Slider blueSlider;

@FXML private Slider alphaSlider;

@FXML private Rectangle colorRectangle;

@FXML private RadioButton smallRadioButton;

@FXML private RadioButton mediumRadioButton;

@FXML private RadioButton largesmallRadioButton;

@FXML private ToggleGroup sizeToggleGroup;

@FXML private Button undoButton;

@FXML private Button clearButton;

@FXML private Pane drawingAreaPane;

// instance variables for managing Painter state

private PenSize radius = PenSize.MEDIUM; // radius of circle

private Paint brushColor = Color.rbg (red, green, blue, alpha); // drawing color

// set user data for the RadioButtons

public void initialize() {

// user data on a control can be any Object

smallRadioButton.setUser(PenSize.SMALL);

mediumRadioButton.setUser(PenSize.MEDIUM);

largeRadioButton.setUser(PenSize.LARGE);

redSlider.valueProperty().addListener (new ChangeListerner() {

@Override

public void changed(ObservableValue ov, Number newValue) {

red = newValue.intValue();

colorRectangle.setFill(Color.rgb(red, green, blue, alpha));

brushColor = Color.rgb(red, green, blue, alpha);

}

});

greenSlider.valueProperty().addListener (new ChangeListerner() {

@Override

public void changed(ObservableValue ov, Number newValue) {

green = newValue.intValue();

colorRectangle.setFill(Color.rgb(red, green, blue, alpha));

brushColor = Color.rgb(red, green, blue, alpha);

}

});

blueSlider.valueProperty().addListener (new ChangeListerner() {

@Override

public void changed(ObservableValue ov, Number newValue) {

blue = newValue.intValue();

colorRectangle.setFill(Color.rgb(red, green, blue, alpha));

brushColor = Color.rgb(red, green, blue, alpha);

}

});

alphaSlider.valueProperty().addListener (new ChangeListerner() {

@Override

public void changed(ObservableValue ov, Number newValue) {

alpha = newValue.intValue();

colorRectangle.setFill(Color.rgb(red, green, blue, alpha));

brushColor = Color.rgb(red, green, blue, alpha);

}

});

}

// handles drawingArea's onMouseDragged MouseEvent

@FXML

private void drawingAreaMouseDragged(MouseEvent e) {

Circle newCircle = new Circle(e.getX(), e.getY(),

radius.getRadius(), brushColor);

drawingAreaPane.getChildren().add(newCircle);

}

// handles size RadioButton's ActionEvents

@FXML

private void sizeRadioButtonSelected(ActionEvent e) {

// user data for each size RadioButton is the corresponding PenSize

radius =

(PenSize) sizeToggleGroup.getSelectedToggle().getUserData();

}

// handles Undo Button's ActionEvents

@FXML

private void undoButtonPressed(ActionEvent event) {

int count = drawingAreaPane.getChildren().size();

// if there are any shapes remove the last one added

if (count > 0) {

drawingAreaPane.getChildren().remove(count - 1);

}

}

// handles Clear Button's ActionEvents

@FXML

private void clearButtonPressed(ActionEvent event) {

drawingAreaPane.getChildren().clear(); // clear the canvas

}

}

trying to post fxml file, but chegg says its too long, so formatting is bad

//Painter.fxml////////////

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!