写在前面
上一节介绍了学生界面的开发,这一节介绍管理员界面的设计,因为业务逻辑差不多,就简单的叙述了。
一、管理员主界面
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="studentSystem.controller.admin.AdminMainController">
<children>
<MenuBar layoutY="-2.0" prefHeight="35.0" prefWidth="1000.0">
<menus>
<Menu mnemonicParsing="false" text="查询">
<items>
<MenuItem fx:id="queryAllStudent" onAction="#queryAllStudentEvent" mnemonicParsing="false" text="查询所有学生" />
<MenuItem fx:id="queryAllTeacher" onAction="#queryAllTeacherEvent" mnemonicParsing="false" text="查询所有教师" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="添加用户">
<items>
<MenuItem fx:id="addTeacher" onAction="#addTeacherEvent" mnemonicParsing="false" text="添加教师" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="个人中心">
<items>
<!--<MenuItem fx:id="queryAdminInfo" onAction="#queryAdminInfoEvent" mnemonicParsing="false" text="查看个人信息" />-->
<MenuItem fx:id="exitSys" onAction="#exitSystem" mnemonicParsing="false" text="退出系统" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="关于">
<items>
<MenuItem fx:id="showDesc" mnemonicParsing="false" text="简介" />
<MenuItem fx:id="callUs" mnemonicParsing="false" text="联系我们" />
</items>
</Menu>
</menus>
</MenuBar>
<AnchorPane fx:id="mainFrameAnchorPane" layoutY="33.0" prefHeight="565.0" prefWidth="1000.0">
<children>
<HBox prefHeight="565.0" prefWidth="1000.0" alignment="CENTER">
<children>
<ImageView fx:id="backgroundView" fitHeight="565.0" fitWidth="1000.0" pickOnBounds="true" preserveRatio="true" />
</children>
</HBox>
</children>
</AnchorPane>
</children>
</AnchorPane>
package studentSystem.controller.admin;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import studentSystem.Main;
import studentSystem.utils.SimpleTools;
import java.io.IOException;
/**
* @author D.hu
* @date 2020/12/6
* @desc
*/
public class AdminMainController {
private SimpleTools simpleTools = new SimpleTools();
@FXML
private MenuItem queryAllTeacher;
@FXML
private AnchorPane mainFrameAnchorPane;
@FXML
private MenuItem queryAllStudent;
@FXML
private ImageView backgroundView;
@FXML
private MenuItem addTeacher;
@FXML
private MenuItem exitSys;
@FXML
private MenuItem callUs;
@FXML
private MenuItem showDesc;
public void initialize() {
MenuItem[] labeleds = {
queryAllStudent, queryAllTeacher, addTeacher, exitSys, callUs, showDesc};
String[] imagePaths = {
"src/studentSystem/images/fly1.png", "src/studentSystem/images/fly2.png",
"src/studentSystem/images/add1.png", "src/studentSystem/images/logout.png","src/studentSystem/images/phone2.png", "src/studentSystem/images/desc.png"};
simpleTools.setMenuItemImage(labeleds, imagePaths);
// 设置图片
backgroundView.setImage(new Image("file:src/studentSystem/images/bg2.png"));
}
public void queryAllStudentEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initQueryAllStudentFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void queryAllTeacherEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initQueryAllTeacherFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void addTeacherEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initAddTeacherFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void exitSystem(ActionEvent actionEvent) {
System.exit(0);
}
}
二、查询学生
查询学生管理员只需要知道学生的信息就好了,不需要对于学生进行修改。修改的业务就直接交给教师。
这个是界面的截图,主要元素就是表格、标签、文本框、按钮。这些都是自己使用scene builder自动生成的。代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="565.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="studentSystem.controller.admin.QueryAllStudentController">
<children>
<VBox prefHeight="565.0" prefWidth="1000.0">
<children>
<HBox alignment="CENTER" prefHeight="68.0" prefWidth="1000.0">
<children>
<Label fx:id="infoLabel" prefHeight="47.0" prefWidth="357.0" text=" 学 生 信 息">
<font>
<Font name="System Bold" size="28.0" />
</font>
</Label>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="1000.0">
<children>
<Label fx:id="queryNameLabel" prefHeight="20.0" prefWidth="70.0" text="姓名:" />
<TextField fx:id="inputName" prefHeight="30.0" prefWidth="99.0" />
<Label fx:id="queryStudentNumLabel" prefHeight="20.0" prefWidth="70.0" text="学号:">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</Label>
<TextField fx:id="inputStudentNum" prefHeight="30.0" prefWidth="123.0" />
<Button fx:id="queryButton" mnemonicParsing="false" onAction="#queryStudent" prefHeight="30.0" prefWidth="100.0" text="查询">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</Button>
<Button fx:id="resetQueryButton" mnemonicParsing="false" onAction="#reset" prefHeight="30.0" prefWidth="100.0" text="重置">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="446.0" prefWidth="1000.0">
<children>
<TableView fx:id="studentTableView" prefHeight="446.0" prefWidth="638.0">
<columns>
<TableColumn fx:id="studentNumTableColumn" prefWidth="120.0" text="学号" />
<TableColumn fx:id="usernameTableColumn" prefWidth="90.0" text="用户名" />
<TableColumn fx:id