JavaFX + MySql 实现学生信息管理系统
资源内容介绍
详情请看 package sample;import javafx.application.Application;import javafx.beans.value.ChangeListener;import javafx.beans.value.ObservableValue;import javafx.geometry.Insets;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.control.cell.PropertyValueFactory;import javafx.scene.image.Image;import javafx.scene.layout.*;import javafx.scene.paint.Color;import javafx.scene.text.Font;import javafx.scene.text.FontPosture;import javafx.scene.text.FontWeight;import javafx.stage.Stage;import javafx.util.Callback;import java.util.ArrayList;public class View extends Application { // 登录学生学号 private static int id; private static Stage stage; // 提示框数目 private static int number = 0; // 增删改查的页面数 private static int anum = 0; private static Student student0; private static Image img=new Image("D:\\JAVA\\id\\JavaFX\\image\\bg1.jpg"); private static BackgroundImage bImg = new BackgroundImage(img, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT); private static Background bGround = new Background(bImg); @Override public void start(Stage stage) throws Exception {// 将舞台复制给静态属性 View.stage = stage; stage.setTitle("学生信息管理系统");// 设置窗口大小不可调节 stage.setResizable(false);// 登录 login(); stage.show(); } // 登录界面 static void login() { // 新建布局 GridPane gp = new GridPane();// 设置居中方式 gp.setAlignment(Pos.CENTER);// 调整空隙 gp.setHgap(10); gp.setVgap(20);// 新建文本标签 Label l1 = new Label("学号"); TextField idt = new TextField();// 用户密码 Label l2 = new Label("密码");// 字体 Font fon1 = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20); l1.setFont(fon1); l2.setFont(fon1);// 新建密码框 PasswordField pwd = new PasswordField();// 按钮的创建 Button b1 = new Button("登录"); Button b2 = new Button("注册"); // 单选框:学生,老师 ToggleGroup group = new ToggleGroup(); RadioButton student = new RadioButton("学生"); RadioButton manager = new RadioButton("管理员"); HBox h1 = new HBox(); student.setToggleGroup(group); manager.setToggleGroup(group);// 添加单选按钮监听 group.selectedToggleProperty().addListener((observable, oldValue, newValue) -> { if (newValue.equals(student)) { //单选按钮为学生 l1.setText("学号"); b1.setOnAction(actionEvent -> { try { if (Connect.login(Integer.valueOf(idt.getText()), pwd.getText()) > 0) { id=Integer.valueOf(idt.getText()); homepage(); } else { if (number == 0) { tips("登陆失败"); } } } catch (Exception e) { e.printStackTrace(); } }); // 注册按钮事件 b2.setOnAction(actionEvent -> { BorderPane bp = new BorderPane(); add(bp); });// 设置”注册“按钮可见 b2.setVisible(true); } else if (newValue.equals(manager)) {// 设置”注册“按钮不可见 b2.setVisible(false); l1.setText("姓名"); b1.setOnAction(actionEvent -> { try { if (Connect.maglogin(idt.getText(), pwd.getText())) { maghomepage(); } else { if (number == 0) { tips("登录失败"); } } ; } catch (Exception e) { e.printStackTrace(); } }); } }); h1.getChildren().addAll(student, manager);// 背景图片 gp.setBackground(bGround); // 添加画板 gp.add(l1, 0, 0); gp.add(idt, 1, 0); gp.add(l2, 0, 1); gp.add(pwd, 1, 1); gp.add(b1, 0, 2); gp.add(b2, 1, 2); gp.add(h1, 1, 3); Scene sc = new Scene(gp, 400, 300); stage.setScene(sc); } // 学生操作界面 static void homepage() {// 创建文本 Label l5 = new Label("学生查询系统"); Button l1 = new Button("个人信息"); Button l3 = new Button("成绩查询"); Button l4 = new Button("返回登录");// 设置字体颜色 l1.setTextFill(Color.BLUE); l3.setTextFill(Color.BLUE); l4.setTextFill(Color.BLUE);// 设置字体大小 Font fon1 = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 30); Font fon2 = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20); l5.setFont(fon1); l1.setFont(fon2); l3.setFont(fon2); l4.setFont(fon2);// 学生信息查询 l1.setOnAction(actionEvent -> { query(); });// 成绩查询 l3.setOnAction(actionEvent -> { try { score(id); } catch (Exception e) { e.printStackTrace(); } });// 返回登陆 l4.setOnAction(actionEvent -> { login(); });// 添加面板 VBox bv = new VBox(50, l5, l1, l3, l4); bv.setAlignment(Pos.CENTER); bv.setBackground(bGround); Scene sc = new Scene(bv, 500, 600); stage.setScene(sc); } // 管理员操作界面 static void maghomepage() {// 创建文本 Label l5 = new Label("学生查询系统"); Button l1 = new Button("学生信息管理"); Button l2 = new Button("学生成绩管理"); Button l3 = new Button("返回登陆");// 设置字体颜色 l1.setTextFill(Color.BLUE); l2.setTextFill(Color.BLUE); l3.setTextFill(Color.BLUE);// 设置字体大小 Font fon1 = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 30); Font fon2 = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20); l5.setFont(fon1); l1.setFont(fon2); l2.setFont(fon2); l3.setFont(fon2);// 学生信息管理 l1.setOnAction(actionEvent -> { magquery(); });// 学生成绩管理 l2.setOnAction(actionEvent -> { magscore(); });// 返回登陆 l3.setOnAction(actionEvent -> { login(); });// 添加面板 VBox bv = new VBox(50, l5, l1, l2, l3); bv.setAlignment(Pos.CENTER); bv.setBackground(bGround); Scene sc = new Scene(bv, 500, 600); stage.setScene(sc); } // 学生信息查询界面 static void query() { BorderPane bp = new BorderPane();// 顶部 FlowPane fp1 = new Flo