① 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,这样能达到想要的效果了,但是这样的缺点是不通用,组件不独立,想办法改进中