国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java UI組件和多媒體

這篇具有很好參考價(jià)值的文章主要介紹了Java UI組件和多媒體。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

目錄

1、使用單選按鈕

2、選擇幾何圖形

?3、交通信號(hào)燈

?4、演示TextField的屬性

5、演示TextArea的屬性

6、選擇一種字體

?7、演示 Label 的屬性

?8、使?用ComboBox 和 ListView?

9、使?用 ScrollBar 和 Slider ?

?10、模擬:一個(gè)轉(zhuǎn)動(dòng)的風(fēng)扇


1、使用單選按鈕

編寫一個(gè) GUI 程序如圖所示可以使用按鈕將消息進(jìn)行左右移動(dòng),并且使用單選按鈕來(lái)修改消息顯示的顏色。

Java UI組件和多媒體

?代碼

package GUI_Practice;

import GUI_basis.ButtonDemo;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

public class ChangeColorWithRadioButton extends ButtonDemo {
	protected BorderPane getPane() {
		BorderPane pane = super.getPane();

		HBox paneForRadioButtons = new HBox();
		paneForRadioButtons.setPadding(new Insets(5, 5, 5, 5));
		paneForRadioButtons.setStyle("-fx-border-color:green");
		paneForRadioButtons.setStyle("-fx-border-width:2px;-fx-border-color:green");

		RadioButton rbRed = new RadioButton("Red");
		RadioButton rbGreen = new RadioButton("Green");
		RadioButton rbBlue = new RadioButton("Blue");
		RadioButton rbOrange = new RadioButton("Orange");
		RadioButton rbYellow = new RadioButton("Yellow");
		RadioButton rbPink = new RadioButton("Pink");
		paneForRadioButtons.getChildren().addAll(rbRed, rbGreen, rbBlue, rbOrange, rbYellow, rbPink);
		pane.setTop(paneForRadioButtons);

		ToggleGroup group = new ToggleGroup();
		rbRed.setToggleGroup(group);
		rbGreen.setToggleGroup(group);
		rbBlue.setToggleGroup(group);
		rbOrange.setToggleGroup(group);
		rbYellow.setToggleGroup(group);
		rbPink.setToggleGroup(group);

		rbRed.setOnAction(e -> {
			if (rbRed.isSelected())
				text.setFill(Color.RED);
		});
		rbGreen.setOnAction(e -> {
			if (rbGreen.isSelected())
				text.setFill(Color.GREEN);
		});
		rbBlue.setOnAction(e -> {
			if (rbBlue.isSelected())
				text.setFill(Color.BLUE);
		});
		rbOrange.setOnAction(e -> {
			if (rbOrange.isSelected())
				text.setFill(Color.ORANGE);
		});
		rbYellow.setOnAction(e -> {
			if (rbYellow.isSelected())
				text.setFill(Color.YELLOW);
		});
		rbPink.setOnAction(e -> {
			if (rbPink.isSelected())
				text.setFill(Color.PINK);
		});
		
		return pane;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

2、選擇幾何圖形

編寫一個(gè)繪制各種幾何圖形的程序,如圖所示。用戶從單選按鈕中選擇 一個(gè)幾何圖形,并且使用復(fù)選框指定是否被填充。

?Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.CheckBox;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;

public class DrawGeometry extends Application {
	protected Circle circle = new Circle(50);
	protected Rectangle rectangle = new Rectangle(100, 50);
	protected Ellipse ellipse = new Ellipse(80, 50);

	protected BorderPane getPane() {
		BorderPane pane = new BorderPane();

		HBox paneForRadioButtons = new HBox(20);
		paneForRadioButtons.setPadding(new Insets(5, 5, 5, 5));

		RadioButton rbCircle = new RadioButton("Circle");
		RadioButton rbRectangle = new RadioButton("Rectangle");
		RadioButton rbEllipse = new RadioButton("Ellipse");
		CheckBox chkFill = new CheckBox("Fill");
		paneForRadioButtons.getChildren().addAll(rbCircle, rbRectangle, rbEllipse, chkFill);
		paneForRadioButtons.setAlignment(Pos.CENTER);

		ToggleGroup group = new ToggleGroup();
		rbCircle.setToggleGroup(group);
		rbRectangle.setToggleGroup(group);
		rbEllipse.setToggleGroup(group);

		pane.setBottom(paneForRadioButtons);

		StackPane paneForGeometry = new StackPane();
		pane.setCenter(paneForGeometry);

		circle.setStroke(Color.BLACK);
		circle.setFill(Color.WHITE);
		rectangle.setStroke(Color.BLACK);
		rectangle.setFill(Color.WHITE);
		ellipse.setStroke(Color.BLACK);
		ellipse.setFill(Color.WHITE);

		rbCircle.setOnAction(e -> {
			if (rbCircle.isSelected())
				paneForGeometry.getChildren().add(circle);
		});
		rbRectangle.setOnAction(e -> {
			if (rbRectangle.isSelected())
				paneForGeometry.getChildren().add(rectangle);
		});
		rbEllipse.setOnAction(e -> {
			if (rbEllipse.isSelected())
				paneForGeometry.getChildren().add(ellipse);
		});
		EventHandler<ActionEvent> handler = e -> {
			if (rbCircle.isSelected())
				circle.setFill(Color.GREEN);
			else if (rbRectangle.isSelected())
				rectangle.setFill(Color.GREEN);
			else
				ellipse.setFill(Color.GREEN);
		};
		chkFill.setOnAction(handler);

		return pane;
	}

	public void start(Stage primaryStage) {
		Scene scene = new Scene(getPane(), 450, 200);
		primaryStage.setTitle("DrawGeometry");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

?3、交通信號(hào)燈

編寫一個(gè)程序來(lái)模擬交通信號(hào)燈。程序可以讓用戶從紅、綠三種顔色燈中 選擇一種。當(dāng)選擇一個(gè)單選按鈕后,相應(yīng)的燈被打開,并且一次只能亮一種燈如圖所示)。程序開始時(shí)所有的燈都是不亮的。

Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.CheckBox;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;

public class ShowTrafficLight extends Application {
	protected Circle circle1 = new Circle(40);
	protected Circle circle2 = new Circle(40);
	protected Circle circle3 = new Circle(40);

	protected BorderPane getPane() {
		BorderPane pane = new BorderPane();

		HBox paneForRadioButtons = new HBox(20);
		paneForRadioButtons.setPadding(new Insets(5, 5, 5, 5));

		RadioButton rbRed = new RadioButton("Red");
		RadioButton rbYellow = new RadioButton("Yellow");
		RadioButton rbGreen = new RadioButton("Green");
		paneForRadioButtons.getChildren().addAll(rbRed, rbYellow, rbGreen);
		paneForRadioButtons.setAlignment(Pos.CENTER);

		pane.setBottom(paneForRadioButtons);

		VBox paneForLights = new VBox(10);
		paneForLights.setPadding(new Insets(5, 5, 5, 5));

		circle1.setStroke(Color.BLACK);
		circle1.setFill(Color.WHITE);
		circle2.setStroke(Color.BLACK);
		circle2.setFill(Color.WHITE);
		circle3.setStroke(Color.BLACK);
		circle3.setFill(Color.WHITE);
		paneForLights.getChildren().addAll(circle1, circle2, circle3);
		paneForLights.setAlignment(Pos.CENTER);

		pane.setCenter(paneForLights);

		rbRed.setOnAction(e -> {
			if (rbRed.isSelected())
				circle1.setFill(Color.RED);
		});
		rbYellow.setOnAction(e -> {
			if (rbYellow.isSelected())
				circle2.setFill(Color.YELLOW);
		});
		rbGreen.setOnAction(e -> {
			if (rbGreen.isSelected())
				circle3.setFill(Color.GREEN);
		});
		return pane;
	}

	public void start(Stage primaryStage) {
		Scene scene = new Scene(getPane(), 400, 400);
		primaryStage.setTitle("BorderPane");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

?4、演示TextField的屬性

編寫一個(gè)程序,動(dòng)態(tài)地設(shè)置文本域的水平對(duì)齊屬性和列寬厲性如圖所示。

Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.RadioButton;

public class ShowPropertiesOfTextField extends Application {
	protected BorderPane getPane() {
		BorderPane pane = new BorderPane();
		// 創(chuàng)建放置Text Field及其Label的面板
		BorderPane paneForTextField = new BorderPane();
		paneForTextField.setPadding(new Insets(5, 5, 5, 5));
		paneForTextField.setLeft(new Label("TextField"));
		// 創(chuàng)建Text Field
		TextField tf = new TextField();
		tf.setAlignment(Pos.BOTTOM_RIGHT);
		paneForTextField.setCenter(tf);

		pane.setTop(paneForTextField);
		// 創(chuàng)建放置單選按鈕的面板
		HBox paneForRadioButtons = new HBox(10);
		RadioButton rbLeft = new RadioButton("Left");
		RadioButton rbCenter = new RadioButton("Center");
		RadioButton rbRight = new RadioButton("Right");
		// 設(shè)置列寬屬性的文本域和標(biāo)簽
		Label label = new Label("Column Size");
		TextField tfColumnSize = new TextField();
		tfColumnSize.setAlignment(Pos.BOTTOM_RIGHT);

		paneForRadioButtons.getChildren().addAll(rbLeft, rbCenter, rbRight, label, tfColumnSize);
		paneForRadioButtons.setAlignment(Pos.BOTTOM_CENTER);

		pane.setBottom(paneForRadioButtons);

		rbLeft.setOnAction(e -> tf.setAlignment(Pos.BOTTOM_LEFT));
		rbCenter.setOnAction(e -> tf.setAlignment(Pos.BOTTOM_CENTER));
		rbRight.setOnAction(e -> tf.setAlignment(Pos.BOTTOM_RIGHT));
		tfColumnSize.setOnAction(e -> tf.setPrefColumnCount(Integer.valueOf(tfColumnSize.getText())));

		return pane;
	}
	public void start(Stage primaryStage) {
		Scene scene = new Scene(getPane());
		primaryStage.setTitle("ShowPropertiesOfTextField");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

5、演示TextArea的屬性

編寫一個(gè)程序,演示文本域的屬性,程序使用復(fù)選框表明文本是否換行,如圖所示

?Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class ShowPropertiesOfTextArea extends Application {
	public void start(Stage primaryStage) {
		BorderPane pane = new BorderPane();

		HBox paneForCheckBoxes = new HBox(10);
		paneForCheckBoxes.setPadding(new Insets(5, 5, 5, 5));
		CheckBox chkEditable = new CheckBox("Editable");
		CheckBox chkWrap = new CheckBox("Wrap");
		paneForCheckBoxes.getChildren().addAll(chkEditable, chkWrap);
		paneForCheckBoxes.setAlignment(Pos.CENTER);

		TextArea textArea = new TextArea();
		textArea.setEditable(false);
		textArea.setWrapText(false);
		ScrollPane sbHorizontal = new ScrollPane();
		ScrollBar sbVertical = new ScrollBar();
		sbVertical.setOrientation(Orientation.VERTICAL);

		pane.setCenter(textArea);
		pane.setBottom(sbHorizontal);
		pane.setRight(sbVertical);
		pane.setBottom(paneForCheckBoxes);

		chkEditable.setOnAction(e -> textArea.setEditable(true));
		chkWrap.setOnAction(e -> textArea.setWrapText(true));

		Scene scene = new Scene(pane, 800, 400);
		primaryStage.setTitle("ShowPropertiesOfTextArea");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

6、選擇一種字體

編寫一個(gè)程序,可以動(dòng)態(tài)地改變堆棧面板上顯示的標(biāo)簽中文本的字體這個(gè)

消息可以同時(shí)以粗體和斜體顯示 。 可以從組合框中選擇字體名和字體大小 如圖 所示。 使用 Font .getFamilies()? 可以得到可用的宇體名 。字體大小的組合框初始化為從 1到 100 之間的數(shù)字。

?Java UI組件和多媒體

?代碼

package GUI_Practice;

import GUI_basis.DescriptionPane;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.scene.control.Label;
import javafx.scene.control.ComboBox;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class CheckFont extends Application {
	private Text text = new Text("Programming is fun");
	private String[] fontNames = { "SimSun", "SimHei", "Microsoft YaHei", "KaiTi", "LiSu" };
	private String[] fontSize = new String[50];
	private ComboBox<String> cbo1 = new ComboBox<>();
	private ComboBox<String> cbo2 = new ComboBox<>();
	private DescriptionPane descriptionPane = new DescriptionPane();

	public void start(Stage primaryStage) {
		BorderPane pane = new BorderPane();

		HBox paneForComboBox = new HBox(10);
		Label lblFontName = new Label("Font Name");
		Label lblFontSize = new Label("Font Size");
		paneForComboBox.getChildren().addAll(lblFontName, cbo1, lblFontSize, cbo2);

		pane.setTop(paneForComboBox);
		cbo1.setPrefWidth(200);
		cbo1.setValue("SimSun");

		cbo2.setPrefWidth(50);
		cbo2.setValue("20");

		for (int i = 0; i < 50; i++)
			fontSize[i] = (i + 20) + "";

		ObservableList<String> items1 = FXCollections.observableArrayList(fontNames);
		cbo1.getItems().addAll(items1);
		pane.setCenter(text);

		cbo1.setOnAction(e -> setDisplay1(items1.indexOf(cbo1.getValue())));

		ObservableList<String> items2 = FXCollections.observableArrayList(fontSize);
		cbo2.getItems().addAll(items2);

		cbo2.setOnAction(e -> setDisplay2(items2.indexOf(cbo2.getValue())));

		Scene scene = new Scene(pane, 500, 200);
		primaryStage.setTitle("CheckFont");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public void setDisplay1(int index) {
		Font font = new Font(fontNames[index], text.getFont().getSize());
		text.setFont(font);
	}

	public void setDisplay2(int index) {
		text.setFont(new Font(Double.valueOf(fontSize[index])));
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

?7、演示 Label 的屬性

?編 寫 一 個(gè) 程 序,允 許 用 戶 動(dòng) 態(tài) 地 設(shè) 置 屬 性 contentDisplay和 graphicTextCap, 如圖所示。

Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class ShowPropertiesOfLabel extends Application {
	public void start(Stage primaryStage) {
		BorderPane pane = new BorderPane();

		HBox hbox = new HBox(10);
		hbox.setPadding(new Insets(5, 5, 5, 5));

		ComboBox<String> cbo = new ComboBox<>();
		TextField tf = new TextField();

		hbox.getChildren().addAll(new Label("contentDisplay"), cbo, new Label("graphicTextGap"), tf);
		pane.setTop(hbox);

		Label lbl = new Label("grapes", new ImageView("image/grapes.jpg"));
		lbl.setStyle("-fx-border-color:purple;-fx-border-width:2");
		lbl.setContentDisplay(ContentDisplay.LEFT);

		pane.setCenter(lbl);

		String[] contentDisplay = { "LEFT", "RIGHT", "CENTER" };
		ObservableList<String> items = FXCollections.observableArrayList(contentDisplay);
		cbo.getItems().addAll(items);

		cbo.setOnAction(e -> {
			if (cbo.getValue() == "LEFT")
				lbl.setContentDisplay(ContentDisplay.LEFT);
			if (cbo.getValue() == "RIGHT")
				lbl.setContentDisplay(ContentDisplay.RIGHT);
			if (cbo.getValue() == "CENTER")
				lbl.setContentDisplay(ContentDisplay.CENTER);
		});
		tf.setOnAction(e -> lbl.setGraphicTextGap(Double.valueOf(tf.getText())));

		Scene scene = new Scene(pane);
		primaryStage.setTitle("ShowPropertiesOfLabel");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

?8、使?用ComboBox 和 ListView?

編寫一個(gè)程序,演示在列表中選擇的條目 。程序用組合框指定 選擇方式, 如圖 所示 。當(dāng)選擇條目后,列表下方的標(biāo)簽中就會(huì)顯示選定項(xiàng)
Java UI組件和多媒體

?代碼

package GUI_Practice;

import GUI_basis.DescriptionPane;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.FlowPane;
import javafx.scene.text.Text;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SelectionMode;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class UseComboBoxAndListView extends Application {

	public void start(Stage primaryStage) {
		BorderPane pane = new BorderPane();

		HBox hbox = new HBox(10);
		ComboBox<String> cbo = new ComboBox<>();
		String[] selectionNode = { "MULTIPLE", "SINGLE" };
		ObservableList<String> items = FXCollections.observableArrayList(selectionNode);
		cbo.getItems().addAll(items);
		hbox.getChildren().addAll(new Label("Choose Selection Node:"), cbo);
		hbox.setAlignment(Pos.CENTER);

		pane.setTop(hbox);

		String[] countries = { "Canada", "China", "Denmark", "France", "Germany", "India" };
		ListView<String> lv = new ListView<>(FXCollections.observableArrayList(countries));
		lv.setPrefSize(400, 400);

		pane.setCenter(lv);

		Text text = new Text("Selected iterms are");
		pane.setBottom(text);

		lv.getSelectionModel().selectedItemProperty().addListener(ov -> {
			if (cbo.getValue() == "MULTIPLE")
				for (Integer i : lv.getSelectionModel().getSelectedIndices())
					text.setText(text.getText() + " " + countries[i] + " ");
			else {
				text.setText("Selected iterms are ");
				for (Integer i : lv.getSelectionModel().getSelectedIndices())
					text.setText(text.getText() + countries[i]);
			}
		});

		Scene scene = new Scene(pane);
		primaryStage.setTitle("UseComboBoxAndListView");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

9、使?用 ScrollBar 和 Slider ?

編寫一個(gè)程序,使用滾動(dòng)條或者滑動(dòng)條選擇文本的顏色,如圖所示 。 使用四個(gè)水平滾動(dòng)條選擇顏色 紅色 、 綠色和藍(lán)色 ) , 以及透明度的百分比

?Java UI組件和多媒體

?代碼

package GUI_Practice;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.paint.*;

public class ShowColors extends Application {
	public void start(Stage primaryStage) {
		VBox pane = new VBox(20);

		HBox hbox = new HBox();
		Text text = new Text("Show Color");
		text.setFont(new Font(30));
		hbox.getChildren().add(text);
		hbox.setAlignment(Pos.CENTER);

		pane.getChildren().add(hbox);

		GridPane paneForSliders = new GridPane();
		paneForSliders.setAlignment(Pos.CENTER);
		Slider sldRed = new Slider();
		Slider sldGreen = new Slider();
		Slider sldBlue = new Slider();
		Slider sldOpadty = new Slider();

		Label lb1 = new Label("Red");
		lb1.setFont(new Font(20));
		Label lb2 = new Label("Green");
		lb2.setFont(new Font(20));
		Label lb3 = new Label("Blue");
		lb3.setFont(new Font(20));
		Label lb4 = new Label("Opacity");
		lb4.setFont(new Font(20));

		paneForSliders.add(lb1, 0, 0);
		paneForSliders.add(sldRed, 1, 0);
		paneForSliders.add(lb2, 0, 1);
		paneForSliders.add(sldGreen, 1, 1);
		paneForSliders.add(lb3, 0, 2);
		paneForSliders.add(sldBlue, 1, 2);
		paneForSliders.add(lb4, 0, 3);
		paneForSliders.add(sldOpadty, 1, 3);

		pane.getChildren().add(paneForSliders);

		sldRed.valueProperty().addListener(ov -> {
			Color color = (Color) text.getFill();
			text.setFill(new Color(sldRed.getValue(), color.getGreen(), color.getBlue(), color.getOpacity()));
		});

		sldGreen.valueProperty().addListener(ov -> {
			Color color = (Color) text.getFill();
			text.setFill(new Color(color.getRed(), sldGreen.getValue(), color.getBlue(), color.getOpacity()));
		});

		sldBlue.valueProperty().addListener(ov -> {
			Color color = (Color) text.getFill();
			text.setFill(new Color(color.getRed(), color.getGreen(), sldBlue.getValue(), color.getOpacity()));
		});

		sldOpadty.valueProperty().addListener(ov -> {
			Color color = (Color) text.getFill();
			text.setFill(new Color(color.getRed(), color.getGreen(), color.getBlue(), sldOpadty.getValue()));
		});
		Scene scene = new Scene(pane, 300, 200);
		primaryStage.setTitle("ShowColors");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}

}

運(yùn)行結(jié)果

Java UI組件和多媒體

?10、模擬:一個(gè)轉(zhuǎn)動(dòng)的風(fēng)扇

增加一個(gè)滑動(dòng)條控制風(fēng)扇的速度如圖所示

Java UI組件和多媒體

?代碼

實(shí)在不會(huì)了啊啊啊啊,先這樣吧,搞了半天了,剩下的下次

ControlFans

package GUI_Practice;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;

public class ControlFans extends Application {

	public void start(Stage primaryStage) {
		BorderPane borderPane = new BorderPane();

		HBox hbox1 = new HBox(20);
		FanBorderPane pane1 = new FanBorderPane(), pane2 = new FanBorderPane(), pane3 = new FanBorderPane();
		hbox1.getChildren().addAll(pane1, pane2, pane3);

		borderPane.setTop(hbox1);

		HBox hbox2 = new HBox(10);
		hbox2.setAlignment(Pos.CENTER);
		Button btStart = new Button("Start All");
		Button btStop = new Button("Stop All");
		hbox2.getChildren().addAll(btStart, btStop);
		borderPane.setBottom(hbox2);

//		EventHandler<ActionEvent> handler1 = e -> {
//			
//		};
//
//		Timeline timeline = new Timeline(new KeyFrame(Duration.millis(20), handler1));
//		timeline.setCycleCount(Timeline.INDEFINITE);
//		timeline.play();
//
//		btStop.setOnMouseClicked(e -> timeline.play());
//		btStart.setOnMouseClicked(e -> timeline.pause());

		Scene scene = new Scene(borderPane);
		primaryStage.setTitle("ControlFans");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}
}

FanPane

package GUI_Practice;

import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;

public class FanPane extends Pane {

	protected Circle circle = new Circle(100, 70, 60);;
	protected Arc[] arc = new Arc[4];
	protected double startAngle = 30;
	protected double increment = 5;

	public FanPane() {
		circle.setStroke(Color.BLACK);
		circle.setFill(Color.WHITE);

		getChildren().add(circle);

		for (int i = 0; i < 4; i++) {
			arc[i] = new Arc(100, 70, 50, 50, startAngle + 90 * i, 30);
			arc[i].setType(ArcType.ROUND);
			arc[i].setFill(Color.BLACK);
			getChildren().add(arc[i]);
		}

	}

	public void setIncrement(double i) {
		increment = i;
	}

	public void setAngle(double angle) {
		startAngle = angle;
		for (int i = 0; i < 4; i++)
			arc[i].setStartAngle(startAngle + 90 * i);
	}

	public void resume() {
		setAngle(startAngle + increment);
	}

	public void reverse() {
		increment *= -1;
	}

}

FanBorderPane文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-484670.html

package GUI_Practice;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.util.Duration;

public class FanBorderPane extends BorderPane {
	protected FanPane pane = new FanPane();
	protected HBox hbox = new HBox();
	protected Timeline timeline;

	public FanBorderPane() {
		hbox.setSpacing(10);
		hbox.setAlignment(Pos.CENTER);

		Button btPause = new Button("Pause");
		Button btResume = new Button("Resume");
		Button btReverse = new Button("Reverse");

		hbox.getChildren().addAll(btPause, btResume, btReverse);

		timeline = new Timeline(new KeyFrame(Duration.millis(20), e -> pane.resume()));
		timeline.setCycleCount(Timeline.INDEFINITE);
		timeline.play();

		btPause.setOnAction(e -> timeline.pause());
		btResume.setOnAction(e -> timeline.play());
		btReverse.setOnAction(e -> pane.reverse());

		Slider sld = new Slider();
		sld.valueProperty().addListener(ov -> {
			pane.setIncrement(sld.getValue());
		});

		setTop(pane);
		setCenter(hbox);
		setBottom(sld);
		BorderPane.setAlignment(hbox, Pos.CENTER);
	}
}

到了這里,關(guān)于Java UI組件和多媒體的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Android多媒體功能開發(fā)(11)——使用AudioRecord類錄制音頻

    Android多媒體功能開發(fā)(11)——使用AudioRecord類錄制音頻

    AudioRecord類優(yōu)點(diǎn)是能錄制到緩沖區(qū),能夠?qū)崿F(xiàn)邊錄邊播(AudioRecord + AudioTrack)以及對(duì)音頻的實(shí)時(shí)處理(如QQ電話)。缺點(diǎn)是輸出是PCM格式的原始采集數(shù)據(jù),如果直接保存成音頻文件,不能夠被播放器播放,所以必須用代碼實(shí)現(xiàn)數(shù)據(jù)編碼以及壓縮。 使用AudioRecord錄音的基本步驟是

    2023年04月09日
    瀏覽(24)
  • 軟考:中級(jí)軟件設(shè)計(jì)師:多媒體基礎(chǔ),音頻,圖像,顏色,多媒體技術(shù)的種類,圖像音頻視頻的容量計(jì)算,常見(jiàn)的多媒體標(biāo)準(zhǔn)

    軟考:中級(jí)軟件設(shè)計(jì)師:多媒體基礎(chǔ),音頻,圖像,顏色,多媒體技術(shù)的種類,圖像音頻視頻的容量計(jì)算,常見(jiàn)的多媒體標(biāo)準(zhǔn)

    提示:系列被面試官問(wèn)的問(wèn)題,我自己當(dāng)時(shí)不會(huì),所以下來(lái)自己復(fù)盤一下,認(rèn)真學(xué)習(xí)和總結(jié),以應(yīng)對(duì)未來(lái)更多的可能性 關(guān)于互聯(lián)網(wǎng)大廠的筆試面試,都是需要細(xì)心準(zhǔn)備的 (1)自己的科研經(jīng)歷, 科研內(nèi)容 ,學(xué)習(xí)的相關(guān)領(lǐng)域知識(shí),要熟悉熟透了 (2)自己的實(shí)習(xí)經(jīng)歷,做了 什

    2024年02月09日
    瀏覽(37)
  • 參會(huì)記錄|全國(guó)多媒體取證暨第二屆多媒體智能安全學(xué)術(shù)研討會(huì)(MAS‘2023)

    參會(huì)記錄|全國(guó)多媒體取證暨第二屆多媒體智能安全學(xué)術(shù)研討會(huì)(MAS‘2023)

    前言 :2023年4月8日上午,我與實(shí)驗(yàn)室的諸位伙伴們共聚浙江杭州西子湖畔的六通賓館,參加了為期一天半的全國(guó)多媒體取證暨第二屆多媒體智能安全學(xué)術(shù)研討會(huì)(MAS’2023)。本屆學(xué)術(shù)研討會(huì)由浙江省自然科學(xué)基金委員會(huì)資助,杭州電子科技大學(xué)承辦。來(lái)自國(guó)內(nèi)多媒體取證與

    2024年02月08日
    瀏覽(116)
  • 多媒體API

    許小墨のBlog —— 菜雞博客直通車 系列文章完整版,配圖更多,CSDN博文圖片需要手動(dòng)上傳,因此文章配圖較少,看不懂的可以去菜雞博客參考一下配圖! 前端系列文章——傳送門 后端系列文章——傳送門 video 只接受幾種視屏格式:ogg、mp4、avi 基本使用: controls屬性,出現(xiàn)

    2024年02月02日
    瀏覽(30)
  • 多媒體音頻焦點(diǎn)淺析

    多個(gè)音源可以同時(shí)向同一個(gè)輸出流進(jìn)行播放音頻,如果沒(méi)有音頻焦點(diǎn)管控,就會(huì)出現(xiàn)多個(gè)音源同時(shí)播放的現(xiàn)象,給用戶帶來(lái)不便;而Android為了避免多個(gè)音源同時(shí)播放,就引入了音頻焦點(diǎn)的概念,所有音頻應(yīng)用都統(tǒng)一按照音頻焦點(diǎn)的規(guī)定執(zhí)行,就可以避免該現(xiàn)象發(fā)生。 當(dāng)應(yīng)用

    2024年02月13日
    瀏覽(37)
  • 多媒體開發(fā)之cgo

    多媒體開發(fā)之cgo

    ???? go語(yǔ)言作為近十年來(lái)優(yōu)秀的現(xiàn)代開發(fā)語(yǔ)言的代表,由于繼承了c語(yǔ)言的簡(jiǎn)潔和很多現(xiàn)代語(yǔ)言的表達(dá)方式,在廣泛的應(yīng)用場(chǎng)景中得到眾多愛(ài)好者的喜愛(ài),如何將go和c、c++進(jìn)行聯(lián)合開發(fā),拓展整個(gè)開發(fā)生態(tài),不用重復(fù)造輪子,掌握cgo可以讓你得心應(yīng)手的在c和go之間傳遞信息,

    2024年02月16日
    瀏覽(27)
  • AIGC生成多媒體流程

    AIGC生成多媒體流程

    給定 生成多個(gè)故事標(biāo)題 多個(gè)故事標(biāo)題進(jìn)行反向推導(dǎo)出 再生成標(biāo)題 直到達(dá)到一個(gè)相似度 多個(gè)標(biāo)題固定總結(jié)合并為一個(gè)標(biāo)題 根據(jù)生成故事多個(gè)章節(jié)標(biāo)題 多個(gè)章節(jié)標(biāo)題反向生成一個(gè)標(biāo)題 對(duì)比前后兩個(gè)標(biāo)題相似度 不斷重復(fù)直到達(dá)到一定相似度 第一個(gè)章

    2024年02月12日
    瀏覽(95)
  • 計(jì)算機(jī)網(wǎng)絡(luò)——多媒體網(wǎng)絡(luò)

    計(jì)算機(jī)網(wǎng)絡(luò)——多媒體網(wǎng)絡(luò)

    通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家, 跳轉(zhuǎn)到網(wǎng)站 我的計(jì)算機(jī)網(wǎng)絡(luò)專欄,是自己在計(jì)算機(jī)網(wǎng)絡(luò)學(xué)習(xí)過(guò)程中的學(xué)習(xí)筆記與心得,在參考相關(guān)教材,網(wǎng)絡(luò)搜素的前提下,結(jié)合自己過(guò)去一段時(shí)間筆記整理,而推出的該專欄,整體架構(gòu)是根據(jù)計(jì)算機(jī)網(wǎng)絡(luò) 自頂向下 方法而整理

    2024年02月20日
    瀏覽(21)
  • HTML5多媒體單元測(cè)試

    (單選題, 10.0分) 為元素指定多個(gè)視頻源使用( )標(biāo)簽(元素)。 A select B datalist C source D src (單選題, 10.0分) 判斷瀏覽器是否支持指定的媒體類型需用到audio或video對(duì)象的( )方法。 A load() B play() C pause() D canPlayType() (多選題, 10.0分) HTML5新增了強(qiáng)大的多媒體的功能,主要體現(xiàn)在

    2024年02月04日
    瀏覽(28)
  • Android多媒體功能開發(fā)(2)——FileProvider

    使用系統(tǒng)多媒體界面需要在我們的應(yīng)用和其他應(yīng)用之間通過(guò)Intent傳遞音頻、圖片、視頻文件的信息。隨著Android版本的升級(jí),對(duì)應(yīng)用數(shù)據(jù)安全性方面的限制越來(lái)越多。 Android 6以后不允許應(yīng)用在外部存儲(chǔ)隨便創(chuàng)建目錄,只能在Android規(guī)定的應(yīng)用自己的文件目錄下創(chuàng)建目錄,該目錄

    2024年02月14日
    瀏覽(27)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包