① eclipse javafx怎麼創建可視化界面
我一直一來都是使用Eclipse進行開發,不太習慣使用NetBeans,於是安裝了JavaFX插件
1. Start up your Java - Eclipse SDK.
2. From the main menu, select Help > Software Updates > Find and Install.
3. In the Install/Update dialog, choose Search for New Features to Install and click Next.
4. Click New Remote Site.
5. In the New Update Site dialog, type JavaFX in the Name field.
6. In the URL field, type
7. Click OK.
8. In the Install window, click Finish.
The Update dialog appears.
9. In the Updates dialog, select JavaFX > JavaFX node > and click Next.
10. Accept the license and click Next.
11. Click Next and Finish
12. In the Verification dialog, select Install All.
不知為何,安裝完成後任然用不到,上網搜,發現Eclipse下進行JavaFX開發還很多缺陷,於是放棄
② javafx怎麼通過表格組件做一個課程表的界面
word中插入表格後「表格」「繪制斜線表頭」選擇樣式二並在右邊分別輸入標題名稱後確定即可
③ JavaFX 如何隱藏Pagination的按鈕
以Pagination的按鈕隱藏為例: 首先打開FX的CSS文檔,了解Pagination的結構, 找到按鈕等所在的子組件,然後讓子組件隱藏即可;
FXCSS文檔; Pagination的結構如下:
所以, 建議還是系統的學習下javaFX,比如fxcss (和HTML的CSS文件比較類似) 以及FXML(結構類似HTML) 稍微閱讀下組件的源代碼即可
④ javaFX如何用Button實現跳轉到一個已創建的fxml界面
可以在「按鈕點擊事件」中寫上讀取fmxl為節點對象
Parent root = FXMLLoader.load(getClass().getResource("fxml_example.fxml"));
然後把父節點放入某個new Scene(root,320,200);
然後在顯示在所用的舞台stage上。
⑤ javaFX怎麼把兩個不同的pane加到一個scene中
這種要並排放置的情況就把一個HBox對象設為Scene的root,然後再把兩個panel放到HBox上即可。由於你只是要界面,計算器的計算邏輯我就不實現了,具體代碼如下(運行環境:jdk8或以上):
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
public class TwoPane extends Application {
final static private int BUTTON_WIDTH = 40;
final static private int BUTTON_HEIGHT = 40;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("簡易計算器");
Label label = new Label("");
label.setAlignment(Pos.CENTER);
label.setMinWidth(100);
HBox expresssionPanel = new HBox(label);
expresssionPanel.setAlignment(Pos.CENTER);
GridPane keyboardPanel = new GridPane();
for(int i = 1; i <= 9; ++i){
Button btn = new Button(String.valueOf(i));
btn.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
btn.setOnAction(e -> label.setText(label.getText() + btn.getText()));
keyboardPanel.add(btn, (i - 1) % 3, i > 3 ? (i > 6 ? 2 : 1) : 0);
}
Button zero = new Button(String.valueOf("0"));
zero.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
zero.setOnAction(e -> label.setText(label.getText() + zero.getText()));
Button plus = new Button(String.valueOf("+"));
plus.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
plus.setOnAction(e -> label.setText(label.getText() + plus.getText()));
Button minus = new Button(String.valueOf("-"));
minus.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
minus.setOnAction(e -> label.setText(label.getText() + minus.getText()));
Button time = new Button(String.valueOf("*"));
time.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
time.setOnAction(e -> label.setText(label.getText() + time.getText()));
Button divide = new Button(String.valueOf("/"));
divide.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
divide.setOnAction(e -> label.setText(label.getText() + divide.getText()));
Button calc = new Button(String.valueOf("="));
calc.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT);
calc.setOnAction(e -> label.setText(label.getText() + calc.getText())/*TODO 計算邏輯代碼待完成*/);
keyboardPanel.add(zero, 0, 3);
keyboardPanel.add(plus, 1, 3);
keyboardPanel.add(minus, 2, 3);
keyboardPanel.add(time, 0, 4);
keyboardPanel.add(divide, 1, 4);
keyboardPanel.add(calc, 2, 4);
HBox root = new HBox(expresssionPanel, keyboardPanel);
HBox.setHgrow(expresssionPanel, Priority.ALWAYS);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
-------------效果如下----------------
⑥ javafx怎麼實現頁面的跳轉
1. 後台
public class Check {
public static boolean checkreturn(String account,String password){
boolean checkbool = false;
if("account".equals(account)&&"password".equals(password)){
checkbool = true;
}
return checkbool;
}
}
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
public class LoginController implements Initializable {
@FXML private TextField account;
@FXML private PasswordField password;
private FXMLTest application;
public void setApp(FXMLTest application){
this.application = application;
}
@FXML
public void LOGIN_M(ActionEvent event) {
application.userlogin(account.getText(), password.getText());
}
@FXML
private void CLEAR_M(ActionEvent event) {
account.setText(null);
password.setText(null);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
public class MainController implements Initializable{
private FXMLTest application;
public void setApp(FXMLTest application){
this.application = application;
}
@FXML
private void OUT_M(ActionEvent event) {
application.useroutmain();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
import check.Check;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class FXMLTest extends Application {
private Stage stage;
private final double MINIMUM_WINDOW_WIDTH = 400.0;
private final double MINIMUM_WINDOW_HEIGHT = 250.0;
@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
stage.setTitle("FXML Login Sample");
stage.setMinWidth(MINIMUM_WINDOW_WIDTH);
stage.setMinHeight(MINIMUM_WINDOW_HEIGHT);
gotologin();
stage.show();
}
public void gotologin(){
try {
LoginController login = (LoginController) replaceSceneContent("FXML_LOGIN.fxml");
login.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void gotomain(){
try {
MainController main = (MainController) replaceSceneContent("FXML_MAIN.fxml");
main.setApp(this);
} catch (Exception ex) {
Logger.getLogger(FXMLTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void userlogin(String account,String password){
if(Check.checkreturn(account,password)){
gotomain();
}
}
public void useroutmain(){
gotologin();
}
private Initializable replaceSceneContent(String fxml) throws Exception {
FXMLLoader loader = new FXMLLoader();
InputStream in = FXMLTest.class.getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(FXMLTest.class.getResource(fxml));
AnchorPane page;
try {
page = (AnchorPane) loader.load(in);
} finally {
in.close();
}
Scene scene = new Scene(page, 800, 600);
stage.setScene(scene);
stage.sizeToScene();
return (Initializable) loader.getController();
}
public static void main(String[] args) {
launch(args);
}
}
2. xml配置
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="250.0" prefWidth="400.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.LoginController">
<children>
<VBox layoutX="3.0" layoutY="0.0" prefHeight="250.0" prefWidth="390.0" spacing="20.0">
<children>
<HBox minHeight="37.0" prefHeight="37.0" prefWidth="411.0">
<children>
<Label text="登陸界面">
<effect>
<DropShadow height="7.845238095238096" radius="4.1815476190476195" width="10.880952380952381" />
</effect>
<font>
<Font name="System Bold" size="30.0" />
</font>
<HBox.margin>
<Insets left="140.0" />
</HBox.margin>
</Label>
</children>
</HBox>
<GridPane alignment="TOP_RIGHT" prefWidth="380.0">
<children>
<Label alignment="TOP_RIGHT" text="Account" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="0">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238096" radius="3.675595238095238" width="8.857142857142858" />
</effect>
<font>
<Font size="25.0" fx:id="x1" />
</font>
<GridPane.margin>
<Insets right="8.0" fx:id="x2" />
</GridPane.margin>
</Label>
<Label font="$x1" text="password" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.margin="$x2" GridPane.rowIndex="1">
<effect>
<DropShadow blurType="TWO_PASS_BOX" height="7.845238095238094" radius="3.6755952380952372" width="8.857142857142854" />
</effect>
</Label>
<TextField fx:id="account" prefHeight="26.0" prefWidth="268.0" promptText="please input your account" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<PasswordField fx:id="password" prefWidth="223.0" promptText="please input your password" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button id="btn_login" mnemonicParsing="false" onAction="#LOGIN_M" prefWidth="80.0" text="登陸" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets top="15.0" />
</GridPane.margin>
</Button>
<Button id="btn_clear" mnemonicParsing="false" onAction="#CLEAR_M" prefWidth="80.0" text="清除" GridPane.columnIndex="1" GridPane.rowIndex="2">
<effect>
<DropShadow />
</effect>
<GridPane.margin>
<Insets left="80.0" top="15.0" />
</GridPane.margin>
</Button>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="205.0" minWidth="10.0" prefWidth="147.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="318.0" minWidth="10.0" prefWidth="243.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
<padding>
<Insets top="30.0" />
</padding>
</VBox>
</children>
</AnchorPane>
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="fxmltest.MainController">
<children>
<Hyperlink layoutX="86.0" layoutY="111.0" text="退出登錄!" onAction="#OUT_M">
<font>
<Font size="45.0" />
</font>
</Hyperlink>
</children>
</AnchorPane>
⑦ 2.Java有哪幾種常見的實現動畫的方法
一: 用多線程播放一組圖片, 實現動畫片的效果; 類似於逐幀動畫,每個圖片是動畫的一幀
二: 在awt/swing界面里, 可以使用paint方法,去繪制圖形,然後用swing提供的Timer或者多線程技術,去刷新繪制的圖形
三:在JavaFX里, 本身就支持動畫,並且封裝了很多動畫效果可以直接使用,比如逐幀動畫.縮放動畫,漸變動畫,旋轉動畫,位置動畫等.
強烈推薦使用javaFX來實現動畫, 因為javaFX是現代化的圖形界面工具,具有簡單,強大,組件豐富,跨平台,支持Html5, 支持表格, 支持動畫等多種優勢
下面是一個javaFX繪制的動態表格
javaFX動態表格
⑧ JavaFX+scenebuilder2.0怎麼連接資料庫實現登錄
下面的代碼就是個簡單的例子。。。
是使用C# 查數據的基本操作。。user是需要驗證的用戶名。。pass 是需要驗證的密碼。
string user = "";
string pass = "";
using (SqlConnection conn = new SqlConnection())
{
SqlConnectionStringBuilder sqlsb = new SqlConnectionStringBuilder();
sqlsb.DataSource = ".\\mssql";
sqlsb.InitialCatalog = "databasename";
sqlsb.IntegratedSecurity = true;
conn.ConnectionString = sqlsb.ConnectionString;
conn.Open(); //打開連接。。。
SqlCommand sqlComm = conn.CreateCommand();
sqlComm.CommandText = "select * from user where user = '"+user+"' and password = '"+pass+"'";
SqlDataReader dr = sqlComm.ExecuteReader();
while (dr.Read())
{
//如果走進來了 表示查到了。。驗證成功,否則失敗。。
}
dr.Close();
conn.Close();
}
⑨ JavaFX界面半透明遮蓋怎麼整
stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.TRANSPARENT);//這是讓彈出窗口透明,如果不設置stage透明,stackpane再怎麼設置也沒用。
FXML:
<StackPane
style="-fx-border-radius:8px;-fx-opacity: 0.4;-fx-background-color: black ;"
xmlns="Java SE | Oracle Technology Network" xmlns:fx="Java SE | Oracle Technology Network"
>
fxml里用css樣式 -fx-opacity: 0.4;控制半透明
以上方法stage顯示後是半透明遮罩效果,但是我想要在stackpane中間一塊區域里放輸入對話框,結果輸入部分還是半透明的效果,還未能解決
追加----換了下實現方式,就是在primaryStage布局中用stackpane,在stackpane的children中添加一個半透明的pane,<Pane fx:id="main_mask" style="-fx-border-radius:8px;-fx-opacity: 0.4;-fx-background-color: black ;" visible="false" />,默認不顯示;在顯示彈出的stage時,再通過代碼設置main_mask顯示,在關閉彈出stage時,隱藏main_mask,這樣能達到想要的效果了,但是這樣的缺點是不通用,組件不獨立,想辦法改進中