5:高颜值JavaFX数据库-九讲之五
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(一)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(二)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(三)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(四)
[高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(五)](当前位置)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(六)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(七)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(八)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(九)
项目效果图
|
|
| |
|
功能点实现
- 实现学生信息的录入
- 实现学生信息的修改
- 实现学生信息的更新
- 实现学生信息的删除
- 添加快捷键使用,方便快速管理
- 使用javafx+fxml+css控制ui样式
- 实现以javafx内部api调用绘制字体特效,无需额外资源调度
- 实现软件图标自定义,增加软件美观度
- 实现拖动窗口即可移动,使更加人性化
- 实现软件英文化,增加可交流性
- 禁用窗口缩放功能,防止ui碰撞
- 添加作者、主页、关闭按钮
- 增加事务弹窗,给予正确提示及错误解决方案
内部优化
- 使用分装思想,将功能块拆分,设立CreateMenu类,统一添加
- 封装错误与信息提示框,统一布局格式
- 封装数据库连接类,无需重复调度
- 采用Lambda表达式绑定事件,无需重写类
- 使用fxml模块化设计标签,方便增改
- 采用css设置样式,统一管理
- 去除不必要的类public,增加软件安全性
- 利用SceneBuilder绘制生成fxml控件,提升编写效率
- 采用不同尺寸图标格式适应多种运行状态
类结构示例
创建其他的面板
1、创建DeleteFxml.fxml面板
和上一章前面的一样,就是把字改一下就行了
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" fx:controller="system.Delete"
hgap="10" vgap="10">
<padding>
<Insets top="25" right="25" bottom="10" left="25" />
</padding>
<Label text="Welcome to Delete:" GridPane.columnSpan="2" stylesheets="/source/Title.css"
GridPane.rowIndex="0" />
<Label text="Please Input Delete Student Number:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="2" />
<TextField fx:id="Number" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox spacing="10" alignment="bottom_right" GridPane.columnIndex="3" GridPane.rowIndex="2">
<Button text="Search" onAction="#SearchButtonAction" stylesheets="/source/Title.css" styleClass="btn"/>
</HBox>
<Label text="Student Name:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="3" />
<TextField fx:id="Name" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Student Gender:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="4" />
<TextField fx:id="Gender" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="Student Address:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="5" />
<TextField fx:id="Address" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label text="Student Phone:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="6" />
<TextField fx:id="Phone" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label text="Student Major:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="7" />
<TextField fx:id="Major" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<HBox spacing="10" alignment="center" GridPane.columnSpan="3" GridPane.rowIndex="10">
<Button text="Delete" onAction="#DeleteButtonAction" stylesheets="/source/Title.css" styleClass="btn"/>
</HBox>
</GridPane>
package system;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextField;
import java.io.IOException;
public class Delete {
@FXML
TextField Number;
@FXML
TextField Name;
@FXML
TextField Gender;
@FXML
TextField Address;
@FXML
TextField Phone;
@FXML
TextField Major;
@FXML
void SearchButtonAction(ActionEvent event) {
}
@FXML
void DeleteButtonAction(ActionEvent event) {
}
Parent createNode() throws IOException {
return FXMLLoader.load(getClass().getResource("../source/DeleteFxml.fxml"));
}
}
2、创建SearchFxml.fxml面板
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" fx:controller="system.Search"
hgap="10" vgap="10">
<padding>
<Insets top="25" right="25" bottom="10" left="25" />
</padding>
<Label text="Welcome to Search:" GridPane.columnSpan="2" stylesheets="/source/Title.css"
GridPane.rowIndex="0" />
<Label text="Please Input Search Student Number:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="2" />
<TextField fx:id="Number" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox spacing="10" alignment="bottom_right" GridPane.columnIndex="3" GridPane.rowIndex="2">
<Button text="Search" onAction="#SearchButtonAction" stylesheets="/source/Title.css" styleClass="btn"/>
</HBox>
<Label text="Student Name:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="3" />
<TextField fx:id="Name" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Student Gender:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="4" />
<TextField fx:id="Gender" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="Student Address:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="5" />
<TextField fx:id="Address" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label text="Student Phone:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="6" />
<TextField fx:id="Phone" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label text="Student Major:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="7" />
<TextField fx:id="Major" GridPane.columnIndex="1" GridPane.rowIndex="7" />
</GridPane>
package system;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.TextField;
import java.io.IOException;
public class Search {
@FXML
TextField Number;
@FXML
TextField Name;
@FXML
TextField Gender;
@FXML
TextField Address;
@FXML
TextField Phone;
@FXML
TextField Major;
@FXML
void SearchButtonAction(ActionEvent event) {
}
Parent createNode() throws IOException {
return FXMLLoader.load(getClass().getResource("../source/SearchFxml.fxml"));
}
}
3、创建UpdateFxml.fxml面板
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" fx:controller="system.Update"
hgap="10" vgap="10">
<padding>
<Insets top="25" right="25" bottom="10" left="25"/>
</padding>
<Label text="Welcome to Update:" GridPane.columnSpan="2" stylesheets="/source/Title.css"
GridPane.rowIndex="0"/>
<Label text="Please Input Search Student Number:" GridPane.columnIndex="0" stylesheets="/source/Title.css"
styleClass="label-oth" GridPane.rowIndex="2"/>
<TextField fx:id="Number" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<HBox spacing="10" alignment="bottom_right" GridPane.columnIndex="3" GridPane.rowIndex="2">
<Button text="Search" onAction="#SearchButtonAction" stylesheets="/source/Title.css" styleClass="btn"/>
</HBox>
<Label text="Student Name:" GridPane.columnIndex="0" GridPane.rowIndex="3" stylesheets="/source/Title.css"
styleClass="label-oth"/>
<TextField fx:id="Name" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="Student Gender:" GridPane.columnIndex="0" GridPane.rowIndex="4" stylesheets="/source/Title.css"
styleClass="label-oth"/>
<TextField fx:id="Gender" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label text="Student Address:" GridPane.columnIndex="0" GridPane.rowIndex="5" stylesheets="/source/Title.css"
styleClass="label-oth"/>
<TextField fx:id="Address" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<Label text="Student Phone:" GridPane.columnIndex="0" GridPane.rowIndex="6" stylesheets="/source/Title.css"
styleClass="label-oth"/>
<TextField fx:id="Phone" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
<Label text="Student Major:" GridPane.columnIndex="0" GridPane.rowIndex="7" stylesheets="/source/Title.css"
styleClass="label-oth"/>
<TextField fx:id="Major" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<HBox spacing="10" alignment="center" GridPane.columnSpan="3" GridPane.rowIndex="10">
<Button text="Update" onAction="#UpdateButtonAction" stylesheets="/source/Title.css" styleClass="btn"/>
</HBox>
</GridPane>
package system;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.TextField;
import java.io.IOException;
public class Update {
@FXML
TextField Number;
@FXML
TextField Name;
@FXML
TextField Gender;
@FXML
TextField Address;
@FXML
TextField Phone;
@FXML
TextField Major;
@FXML
void SearchButtonAction(ActionEvent event) {
}
@FXML
void UpdateButtonAction(ActionEvent event) {
}
Parent createNode() throws IOException {
return FXMLLoader.load(getClass().getResource("../source/UpdateFxml.fxml"));
}
}
关注后续章节,我们会添加更多功能:
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(一)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(二)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(三)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(四)
[高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(五)](当前位置)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(六)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(七)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(八)
高颜值数据库项目实战MySQL+JavaFX+Fxml+CSS(完整精讲解版+源代码)(九)