ugh that lab was fun but draining
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Ellipse;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowElipse1 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(new My32Ellipses(), 800, 600);
|
||||
primaryStage.setTitle("Show 32 Ellipses");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
class My32Ellipses extends Pane {
|
||||
private void paint32Ellipses() {
|
||||
getChildren().clear();
|
||||
// draw 32 rotated ellipses on top of each other
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
// Create an ellipse and add it to the pane
|
||||
Ellipse e1 = new Ellipse(
|
||||
getWidth() / 2, getHeight() / 2,
|
||||
getWidth() / 2 - 120, getHeight() / 2 - 120);
|
||||
e1.setStroke(Color.color(Math.random(),
|
||||
Math.random(),
|
||||
Math.random()
|
||||
)
|
||||
);
|
||||
e1.setFill(Color.WHITE);
|
||||
e1.setRotate(i * 180 / 32);
|
||||
getChildren().add(e1);
|
||||
}
|
||||
}
|
||||
@Override public void setWidth(double width) {
|
||||
super.setWidth(width);
|
||||
paint32Ellipses();
|
||||
}
|
||||
@Override public void setHeight(double height) {
|
||||
super.setHeight(height);
|
||||
paint32Ellipses();
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ImageArray1 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
final String BASE_PATH = "image/flag";
|
||||
ImageView[] images = new ImageView[] {
|
||||
new ImageView(BASE_PATH+"0.gif"),
|
||||
new ImageView(BASE_PATH+"1.gif"),
|
||||
new ImageView(BASE_PATH+"2.gif"),
|
||||
new ImageView(BASE_PATH+"3.gif"),
|
||||
new ImageView(BASE_PATH+"4.gif"),
|
||||
new ImageView(BASE_PATH+"5.gif"),
|
||||
new ImageView(BASE_PATH+"6.gif")
|
||||
};
|
||||
|
||||
// Create a pane to hold the image views
|
||||
Pane hb = new HBox(10);
|
||||
hb.setPadding(new Insets(5, 5, 5, 5));
|
||||
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
images[i].setFitWidth(150);
|
||||
images[i].setFitHeight(100);
|
||||
hb.getChildren().add(images[i]);
|
||||
}
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(hb);
|
||||
primaryStage.setTitle("Flags"); // Set the stage title
|
||||
primaryStage.setScene(scene); // Place the scene in the stage
|
||||
primaryStage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ImageArray2 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
final String BASE_PATH = "image/flag";
|
||||
ImageView[] images = new ImageView[] {
|
||||
new ImageView(BASE_PATH+"0.gif"),
|
||||
new ImageView(BASE_PATH+"1.gif"),
|
||||
new ImageView(BASE_PATH+"2.gif"),
|
||||
new ImageView(BASE_PATH+"3.gif"),
|
||||
new ImageView(BASE_PATH+"4.gif"),
|
||||
new ImageView(BASE_PATH+"5.gif"),
|
||||
new ImageView(BASE_PATH+"6.gif")
|
||||
};
|
||||
|
||||
// Create a pane to hold the image views
|
||||
Pane vb = new VBox(10);
|
||||
vb.setPadding(new Insets(5, 5, 5, 5));
|
||||
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
images[i].setFitWidth(150);
|
||||
images[i].setFitHeight(100);
|
||||
vb.getChildren().add(images[i]);
|
||||
}
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(vb);
|
||||
primaryStage.setTitle("Flags"); // Set the stage title
|
||||
primaryStage.setScene(scene); // Place the scene in the stage
|
||||
primaryStage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowGridPane1 extends Application {
|
||||
|
||||
@Override // Override the start method in the Application class
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
// Create a pane and set its properties
|
||||
GridPane pane = new GridPane();
|
||||
pane.setAlignment(Pos.CENTER);
|
||||
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
|
||||
pane.setHgap(5.5);
|
||||
pane.setVgap(5.5);
|
||||
|
||||
// Place nodes in the pane
|
||||
pane.add(new Label("First Name:"), 0, 0);
|
||||
pane.add(new TextField(), 1, 0);
|
||||
pane.add(new Label("MI"), 0, 1);
|
||||
pane.add(new TextField(), 1, 1);
|
||||
pane.add(new Label("Last Name:"), 0, 2);
|
||||
pane.add(new TextField(), 1, 2);
|
||||
Button button = new Button("Add Name");
|
||||
pane.add(button, 1, 3);
|
||||
GridPane.setHalignment(button, HPos.RIGHT);
|
||||
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(pane);
|
||||
primaryStage.setTitle("ShowGridPane");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowGridPane2 extends Application {
|
||||
|
||||
@Override // Override the start method in the Application class
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
// Create a pane and set its properties
|
||||
GridPane pane = new GridPane();
|
||||
pane.setAlignment(Pos.CENTER);
|
||||
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
|
||||
pane.setHgap(5.5);
|
||||
pane.setVgap(5.5);
|
||||
|
||||
// Place nodes in the pane
|
||||
pane.add(new Label("First Name:"), 0, 0);
|
||||
TextField fName = new TextField();
|
||||
pane.add(fName, 1, 0);
|
||||
pane.add(new Label("MI:"), 0, 1);
|
||||
TextField mInit = new TextField();
|
||||
pane.add(mInit, 1, 1);
|
||||
pane.add(new Label("Last Name:"), 0, 2);
|
||||
TextField lName = new TextField();
|
||||
pane.add(lName, 1, 2);
|
||||
pane.add(new Label("Gender, M/F/nb:"), 0, 3);
|
||||
TextField gender = new TextField();
|
||||
gender.setMaxSize(40, 20);
|
||||
pane.add(gender, 1, 3);
|
||||
Button button = new Button("Add Person");
|
||||
EventHandler eventHnadler = new EventHandler<ActionEvent>(){
|
||||
@Override
|
||||
public void handle(ActionEvent t)
|
||||
{
|
||||
System.out.println("Added person:");
|
||||
System.out.println(fName.getText() + " " + mInit.getText() + " " + lName.getText());
|
||||
System.out.println("Gender: " + gender.getText());
|
||||
|
||||
}
|
||||
};
|
||||
button.setOnAction(eventHnadler);
|
||||
pane.add(button, 0, 4);
|
||||
GridPane.setHalignment(button, HPos.LEFT);
|
||||
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(pane);
|
||||
primaryStage.setTitle("ShowGridPane");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowLine0 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Pane pane = new Pane();
|
||||
Scene scene = new Scene(pane);
|
||||
primaryStage.setTitle("ShowLine"); // Set the stage title
|
||||
primaryStage.setScene(scene); // Place the scene in the stage
|
||||
|
||||
Line line = new Line();
|
||||
line.setStartX(0.0f);
|
||||
line.setStartY(0.0f);
|
||||
line.setEndX(100.0f);
|
||||
line.setEndY(100.0f);
|
||||
|
||||
pane.getChildren().add(line);
|
||||
primaryStage.show(); //Display the stage
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowLine1 extends Application{
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Scene scene = new Scene(new LinePane1(), 200, 200);
|
||||
primaryStage.setTitle("ShowLine"); // Set the stage title
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class LinePane1 extends Pane {
|
||||
|
||||
public LinePane1() {
|
||||
Line line1 = new Line(10, 10, 11, 11);
|
||||
line1.endXProperty().bind(widthProperty().subtract(10));
|
||||
line1.endYProperty().bind(heightProperty().subtract(10));
|
||||
line1.setStrokeWidth(5);
|
||||
line1.setStroke(Color.GREEN);
|
||||
this.getChildren().add(line1);
|
||||
|
||||
Line line2 = new Line(10, 10, 11, 11);
|
||||
line2.startXProperty().bind(widthProperty().subtract(10));
|
||||
line2.endYProperty().bind(heightProperty().subtract(10));
|
||||
line2.setStrokeWidth(5);
|
||||
line2.setStroke(Color.GREEN);
|
||||
this.getChildren().add(line2);
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowLine2 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Scene scene = new Scene(new LinePane1(), 200, 200);
|
||||
primaryStage.setTitle("ShowLine"); // Set the stage title
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LinePane1 extends Pane {
|
||||
|
||||
public LinePane1() {
|
||||
Line line1 = new Line(10, 10, 11, 11);
|
||||
line1.endXProperty().bind(widthProperty().subtract(10));
|
||||
line1.endYProperty().bind(heightProperty().subtract(10));
|
||||
line1.setStrokeWidth(5);
|
||||
line1.setStroke(Color.GREEN);
|
||||
this.getChildren().add(line1);
|
||||
|
||||
Line line2 = new Line(10, 10, 11, 11);
|
||||
line2.startXProperty().bind(widthProperty().subtract(10));
|
||||
line2.endYProperty().bind(heightProperty().subtract(10));
|
||||
line2.setStrokeWidth(5);
|
||||
line2.setStroke(Color.GREEN);
|
||||
this.getChildren().add(line2);
|
||||
|
||||
Line line3 = new Line(10, 10, 0, 0);
|
||||
line3.startXProperty().bind(widthProperty().divide(2));
|
||||
line3.endXProperty().bind(widthProperty().divide(2));
|
||||
line3.endYProperty().bind(heightProperty().subtract(10));
|
||||
line3.setStrokeWidth(10);
|
||||
line3.setStroke(Color.RED);
|
||||
this.getChildren().add(line3);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontPosture;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ShowText1 extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
// Create a pane to hold the texts
|
||||
Pane pane = new Pane();
|
||||
pane.setPadding(new Insets(5, 5, 5, 5));
|
||||
Text text1 = new Text(40, 40, "Java programming is bold and beautiful!");
|
||||
|
||||
text1.setFont(Font.font("Impact", FontWeight.BOLD,
|
||||
FontPosture.ITALIC, 36));
|
||||
pane.getChildren().add(text1);
|
||||
|
||||
Text text2 = new Text(60, 60, "Java Programming is fun\nand Challenging!");
|
||||
pane.getChildren().add(text2);
|
||||
|
||||
Text text3 = new Text(10, 100, "C# Programming is not as beautiful as Java programming!\n Try it!");
|
||||
text3.setFill(Color.RED);
|
||||
text3.setUnderline(true);
|
||||
text3.setStrikethrough(true);
|
||||
text3.rotateProperty().add(90);
|
||||
pane.getChildren().add(text3);
|
||||
|
||||
// Create a scene and place it in the stage
|
||||
Scene scene = new Scene(pane);
|
||||
primaryStage.setTitle("ShowText"); // Set the stage title
|
||||
primaryStage.setScene(scene); // Place the scene in the stage
|
||||
primaryStage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package lab2_fx2_f22_part1;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestArc extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Pane pane = new Pane();
|
||||
|
||||
Arc arc = new Arc();
|
||||
arc.setCenterX(50.0f);
|
||||
arc.setCenterY(50.0f);
|
||||
arc.setRadiusX(25.0f);
|
||||
arc.setRadiusY(25.0f);
|
||||
arc.setStartAngle(45.0f);
|
||||
arc.setLength(270.0f);
|
||||
arc.setType(ArcType.ROUND);
|
||||
|
||||
pane.getChildren().add(arc);
|
||||
Scene scene = new Scene(pane, 400, 300);
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user