今天为大家分享一个java语言编写的教室管理系统,目前系统功能已经很全面,后续会进一步完善。整个系统界面漂亮,有完整得源码,希望大家可以喜欢。喜欢的帮忙点赞和关注。一起编程、一起进步
开发环境
开发语言为Java,开发环境Eclipse或者IDEA都可以,数据为MySQL。运行主程序,或者执行打开JAR文件即可以运行本程序。
系统框架
利用JDK自带的SWING框架开发。纯窗体模式,直接运行Main文件即可以。
系统主要功能
本项目是一个课程设计,主要实现了要给公交查询系统。实现的主要功能包括:按线路查询、按经过站的站查询,按起始站、终止站查询。项目涉及到文件操作、事件处理、数据结构和算法等众多知识点,项目源码完整,下载后可以直接使用。欢迎大家下载。
开发背景
本公交查询系统目标是方便市民进行公交信息查询,并且要做到信息不滞后,其主要思想是做到系统管理的人性化,数据处理的可靠性,可维护性,以及程序的健壮性。
运行方法
下载源码后,导入到Eclipse或者IEDA后,运行MAIN.JAVA,即可以正确运行系统
主要功能
查询功能:系统需要提供几种不同方式的查询手段,以实现灵活方便地管理整个系统。公交查询系统有按线路查询、按经过站的站查询,按起始站-终止站查询3种查询方式
2、数据的更新修改:更新:系统允许管理员级别的用户对数据进行更新、修改并且存盘操作;
运行效果
关键代码
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class GUI extends JFrame {
private JButton btnQuery; // 查询
private JCheckBox ckBox; // 模糊查询选择
private JTextField tfUrbanLine; // 线路名
private JTextField tfBusStation; // 站台名
private JTextField tfSourceStation; // 源站台
private JTextField tfDestStation; // 目的站台
private JTextArea taResult; // 查询结果
private JRadioButton rbStation; // 站站查询
private JRadioButton rbUrbanLine; // 线路查询
private JRadioButton rbStationInfo; //
public GUI() {
initComponents();
initLayout();
loadWindow();
}
/**
* 初始化组件
*/
private void initComponents() {
setTitle("南京公交线路查询系统");// 设置标题
setSize(825, 560); // 窗口大小
setLocation(200, 100); // 窗口初始位置(200,300)
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnQuery = new JButton("查询");
ckBox = new JCheckBox("模糊查询");
tfUrbanLine = new JTextField(10);
tfBusStation = new JTextField(20);
tfSourceStation = new JTextField(20);
tfDestStation = new JTextField(20);
taResult = new JTextArea(70, 50);
rbStation = new JRadioButton("站站查询");
rbUrbanLine = new JRadioButton("线路查询");
rbStationInfo = new JRadioButton("站台信息查询");
taResult.setLineWrap(true);// 设置换行
}
/**
* 初始化窗口布局
*/
private void initLayout() {
JPanel rightPanel = new JPanel(); // 右部面板
JPanel centPanel = new JPanel();// 中间面板
rightPanel.setLayout(new GridLayout(15, 1, 5, 5));
ButtonGroup g = new ButtonGroup();
g.add(rbStation);
g.add(rbStationInfo);
g.add(rbUrbanLine);
rightPanel.add(rbStation);
rightPanel.add(rbStationInfo);// 加入单选按钮
rightPanel.add(rbUrbanLine);
rightPanel.add(new JLabel("请输入起始站点名:"));
rightPanel.add(tfSourceStation);
rightPanel.add(new JLabel("请输入终点站点名:"));
rightPanel.add(tfDestStation);
rightPanel.add(new JLabel("请输入站台名:"));
rightPanel.add(tfBusStation);
rightPanel.add(new JLabel("请输入公交线路名:"));
rightPanel.add(tfUrbanLine);
rightPanel.add(btnQuery);
rightPanel.add(ckBox);
centPanel.add(taResult);// 查询结果放入中间面板
JScrollPane sp = new JScrollPane(centPanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
rightPanel.setBorder(BorderFactory.createTitledBorder("信息区"));// 加入边框
sp.setBorder(BorderFactory.createTitledBorder("查询结果"));
getContentPane().add(rightPanel, BorderLayout.EAST);
getContentPane().add(sp, BorderLayout.CENTER);
btnQuery.addActionListener(new QueryCommand());// 加入监听
rbStation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfSourceStation.setEnabled(true);
tfDestStation.setEnabled(true);
tfUrbanLine.setEnabled(false);
tfBusStation.setEnabled(false);
tfSourceStation.setText("");
tfDestStation.setText("");
tfSourceStation.grabFocus();
}
});
rbStationInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfSourceStation.setEnabled(false);
tfDestStation.setEnabled(false);
tfUrbanLine.setEnabled(false);
tfBusStation.setEnabled(true);
tfBusStation.setText("");
tfBusStation.grabFocus();
}
});
rbUrbanLine.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfSourceStation.setEnabled(false);
tfDestStation.setEnabled(false);
tfUrbanLine.setEnabled(true);
tfBusStation.setEnabled(false);
tfUrbanLine.setText("");
tfUrbanLine.grabFocus();// 获取焦点
}
});
}
/**
* 载入窗口
*/
private void loadWindow() {
setVisible(true); // 显示窗口
tfSourceStation.grabFocus();
taResult.setEditable(false);
rbStation.setSelected(true); // 选中站站查询
tfBusStation.setEnabled(false);
tfUrbanLine.setEnabled(false);
Query.initQuery();// 完成一系列初始化工作
}
// 查询操作
private class QueryCommand implements ActionListener {
public void actionPerformed(ActionEvent e) {
String msg1 = null;
String msg2 = null;
String result = null;
if (rbStation.isSelected()) { // 站站查询
msg1 = tfSourceStation.getText().trim();
if ("".equals(msg1)) {
JOptionPane
.showMessageDialog(GUI.this, "起始站台不能为空!");
tfSourceStation.grabFocus();
return;
}
msg2 = tfDestStation.getText().trim();
if ("".equals(msg2)) {
JOptionPane
.showMessageDialog(GUI.this, "终点站台不能为空!");
tfDestStation.grabFocus();
return;
}
if (ckBox.isSelected()) { // 选中了模糊查询
result = Query.getPathInfo(msg1, msg2, true);
if (result == null)
JOptionPane.showMessageDialog(GUI.this,
"对不起,没有查询到相关乘车方案信息!");
else
taResult.setText(result);
} else {
result = Query.getPathInfo(msg1, msg2, false);
if (result == null)
JOptionPane.showMessageDialog(GUI.this,
"对不起,没有查询到相关乘车方案信息!");
else
taResult.setText(result);
}
} else if (rbStationInfo.isSelected()) {// 查询站台信息
msg1 = tfBusStation.getText().trim();
if ("".equals(msg1)) {
JOptionPane.showMessageDialog(GUI.this, "站台名不能为空!");
tfBusStation.grabFocus();
return;
}
if (ckBox.isSelected()) { // 选中了模糊查询
result = Query.getStationInfo(msg1, true);
} else {
result = Query.getStationInfo(msg1, false);
}
if (result == null)
JOptionPane.showMessageDialog(GUI.this,
"对不起,没有查询到该站台的信息!");
else
taResult.setText(result);
} else if (rbUrbanLine.isSelected()) {// 查询线路信息
msg1 = tfUrbanLine.getText().trim();
if ("".equals(msg1)) {
JOptionPane.showMessageDialog(GUI.this,
"公交线路名不能为空!");
tfUrbanLine.grabFocus();
return;
}
if (ckBox.isSelected()) { // 选中了模糊查询
result = Query.getUrbanLineInfo(msg1, true);
} else {
result = Query.getUrbanLineInfo(msg1, false);
}
if (result == null)
JOptionPane.showMessageDialog(GUI.this,
"对不起,没有查询到该公交线路的信息!");
else
taResult.setText(result);
}
}
}
}