写在前面
上一节介绍了管理员的界面,这一节介绍教师的设计。
一、教师主界面
<?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.teacher.TeacherMainController">
<children>
<MenuBar prefHeight="35.0" prefWidth="1000.0">
<menus>
<Menu mnemonicParsing="false" text="查询">
<items>
<MenuItem fx:id="queryAllStudent" onAction="#teacherQueryStudent" mnemonicParsing="false"
text="查询所有学生信息"/>
<!--<MenuItem fx:id="queryStudentByNum" mnemonicParsing="false" text="根据学号查询学生信息" />-->
<MenuItem fx:id="queryAllSubject" onAction="#queryAllSubjectEvent" mnemonicParsing="false"
text="查询所有学生成绩"/>
<!--<MenuItem fx:id="querySubjectByNum" mnemonicParsing="false" text="根据学号查询学生成绩" />-->
</items>
</Menu>
<Menu mnemonicParsing="false" text="添加">
<items>
<MenuItem fx:id="addStudentInfo" onAction="#addStudentInfoEvent" mnemonicParsing="false"
text="添加学生信息"/>
<MenuItem fx:id="addSubjectInfo" onAction="#addSunbjectInfoEvent" mnemonicParsing="false"
text="添加学生成绩"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="个人中心">
<items>
<!--<MenuItem fx:id="queryTeaInfo" onAction="#queryTeaInfoEvent" mnemonicParsing="false" text="个人信息" />-->
<!--<MenuItem fx:id="updateTeaInfo" onAction="#updateTeaInfo" mnemonicParsing="false" text="修改个人信息" />-->
<MenuItem fx:id="exit" 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="35.0" prefHeight="565.0" prefWidth="1000.0">
<children>
<HBox alignment="CENTER" prefHeight="565.0" prefWidth="1000.0">
<children>
<ImageView fx:id="backgroundView" fitHeight="565.0" fitWidth="1000.0" pickOnBounds="true"
preserveRatio="true"/>
</children>
</HBox>
</children>
</AnchorPane>
</children>
</AnchorPane>
package studentSystem.controller.teacher;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
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 TeacherMainController {
@FXML
private MenuItem queryAllSubject;
@FXML
private MenuItem queryStudentByNum;
@FXML
private AnchorPane mainFrameAnchorPane;
@FXML
private MenuItem queryAllStudent;
@FXML
private MenuItem addSubjectInfo;
@FXML
private ImageView backgroundView;
@FXML
private MenuItem queryTeaInfo;
@FXML
private MenuItem addStudentInfo;
@FXML
private MenuItem querySubjectByNum;
@FXML
private MenuItem updateTeaInfo;
@FXML
private MenuItem callUs;
@FXML
private MenuItem showDesc;
@FXML
private MenuItem exit;
private SimpleTools simpleTools = new SimpleTools();
public void initialize() {
MenuItem[] labeleds = {
queryAllStudent, queryAllSubject, addStudentInfo, addSubjectInfo, exit, callUs, showDesc};
String[] imagePaths = {
"src/studentSystem/images/fly1.png", "src/studentSystem/images/fly2.png",
"src/studentSystem/images/add1.png", "src/studentSystem/images/add2.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 teacherQueryStudent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initTeacherQueryStudentFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void queryAllSubjectEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initQueryAllSubjectFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void addStudentInfoEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initAddStudentInfoFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
public void addSunbjectInfoEvent(ActionEvent actionEvent) throws IOException {
AnchorPane pane = new Main().initAddSubjectInfoFrame();
mainFrameAnchorPane.getChildren().clear();
mainFrameAnchorPane.getChildren().add(pane);
}
// public void queryTeaInfoEvent(ActionEvent actionEvent) throws IOException {
// AnchorPane pane = new Main().initQueryTeaInfoFrame();
// mainFrameAnchorPane.getChildren().clear();
// mainFrameAnchorPane.getChildren().add(pane);
// }
//
// public void updateTeaInfo(ActionEvent actionEvent) throws IOException {
// AnchorPane pane = new Main().initUpdateTeaInfoFrame();
// mainFrameAnchorPane.getChildren().clear();
// mainFrameAnchorPane.getChildren().add(pane);
// }
public void exitSystem(ActionEvent actionEvent) {
System.exit(0);
}
}
二、查询所有学生
因为这些和之前的一样,所以直接把代码放在上面,大家可以去看前面的博客
Main函数中
public AnchorPane initTeacherQueryStudentFrame() throws IOException {
// 加载FXML布局文件
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("view/teacher/TeacherQueryStudentFrame.fxml"));
return loader.load();
}
fxml中
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="565.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="studentSystem.controller.teacher.TeacherQueryStudentController">
<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="#resetQuery" prefHeight="30.0" prefWidth="100.0" text="重置">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="256.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="passwordTableColumn" prefWidth="90.0" text="密码" />
<TableColumn fx:id="nameTableColumn" prefWidth="90.0" text="姓名" />
<TableColumn fx:id="sexTableColumn" prefWidth="60.0" text="性别" />
<TableColumn fx:id="ageTableColumn" prefWidth="70.0" text="年龄" />
<TableColumn fx:id="phoneTableColumn" prefWidth="120.0" text="联系方式" />
</columns>
</TableView>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="140.0" prefWidth="1000.0">
<children>
<VBox prefHeight="122.0" prefWidth="1000.0">
<children>
<HBox alignment="CENTER" prefHeight="137.0" prefWidth="1000.0">
<children>
<VBox alignment="CENTER" prefHeight="137.0" prefWidth="90.0">
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Label fx:id="studentNumLabel" prefHeight="20.0" prefWidth="90.0" text="学号:" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Label fx:id="nameLabel" prefHeight="20.0" prefWidth="90.0" text="姓名:" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Label fx:id="phoneLabel" prefHeight="20.0" prefWidth="90.0" text="联系方式:" />
</children>
</HBox>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="129.0" prefWidth="137.0">
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<TextField fx:id="formStudentNum" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<TextField fx:id="formName" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<TextField fx:id="formPhone" />
</children>
</HBox>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="137.0" prefWidth="82.0">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Label fx:id="usernameLabel" prefHeight="20.0" prefWidth="90.0" text="用户名:" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Label fx:id="sexLabel" prefHeight="20.0" prefWidth="90.0" text="性别:" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" />
</children>