目 录
摘 要 I
ABSTRACT II
前 言 1
第1章 开发语言和开发工具简介 2
1.1 Java技术简介 2
1.1.1 Java语言的特点 2
1.1.2 Java开发工具 3
1.2 GUI技术简介 5
1.2.1 GUI的概述 5
1.2.2 Swing 的概述 5
1.2.3 Swing的特点 6
1.3 JDBC技术简介 6
1.3.1 JDBC概述 6
1.3.2 JDBC的功能 7
1.4 系统的必要性和可行性 7
第2章 系统分析和总体规划 9
2.1需求分析 9
2.2总体设计 9
2.2.1系统功能设计 9
2.2.2运行过程设计 11
2.2.3数据库设计 12
第3章 系统具体设计 13
3.1 数据库表设计 13
3.2 系统界面设计 17
第4章 运行与测试 25
4.1 软件测试的目的和原则 25
4.2 软件的运行与安装 26
4.2.1 J2EE应用程序的构建与部署 26
4.2.2 具体运行过程以及后期维护 26
结 论 28
参考文献 29
致 谢 30
第2章 系统分析和总体规划
2.1需求分析

package GUI;
/*
* GUI交通模拟的主窗口
* */
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
import Logic.impl.ClockTime;
public class MainGUI {
static JFrame f;
private Container c;
private JPanel p1, p2, p3, p5;
private Box b;
private JButton startjb, endjb, selectjb;// 开始,结束,查询按钮
public static JPanel p4;// 设置主画面
public static Timer timer1, timer2, timer3;// 三种灯的计时
public static JLabel[] jl = new JLabel[21];
public static JTextField[] jt = new JTextField[11];// 标记单行文本框,用于输入初始数据
public static JButton[] jb = new JButton[12];// 标记红绿灯的按钮
public static JButton[] jb1 = new JButton[10];// 标记北方向车辆的按钮
public static JButton[] jb11 = new JButton[30];// 标记北方后来车辆的按钮
public static JButton[] jb2 = new JButton[10];// 标记南方向车辆的按钮
public static JButton[] jb22 = new JButton[30];// 标记南方后来车辆的按钮
public static JButton[] jb3 = new JButton[10];// 标记东方向车辆的按钮
public static JButton[] jb33 = new JButton[30];// 标记东方后来车辆的按钮
public static JButton[] jb4 = new JButton[10];// 标记西方向车辆的按钮
public static JButton[] jb44 = new JButton[30];// 标记西方后来车辆的按钮
// 初始化所有的车辆
static {
// 北方开始车辆
for (int i = 0; i < jb1.length; i++) {
jb1[i] = new JButton();
}
// 北方后来车辆
for (int i = 0; i < jb11.length; i++) {
jb11[i] = new JButton();
}
// 南方开始车辆
for (int i = 0; i < jb2.length; i++) {
jb2[i] = new JButton();
}
// 南方后来车辆
for (int i = 0; i < jb22.length; i++) {
jb22[i] = new JButton();
}
// 东方开始车辆
for (int i = 0; i < jb3.length; i++) {
jb3[i] = new JButton(i + "");
}
// 东方后来车辆
for (int i = 0; i < jb33.length; i++) {
jb33[i] = new JButton(i + "");
}
// 西方开始车辆
for (int i = 0; i < jb4.length; i++) {
jb4[i] = new JButton(i + "");
}
// 西方后来车辆
for (int i = 0; i < jb44.length; i++) {
jb44[i] = new JButton(i + "");
}
}
// frame总窗口
public MainGUI() {
f = new JFrame("电子交通模拟系统 ");
c = f.getContentPane();
c.setLayout(new BorderLayout(10, 10));
// p1窗口的左半边
p1 = westJPanel();
p1.setBackground(Color.gray);
c.add(p1, BorderLayout.WEST);
// p2窗口的右半边
p2 = mainJPanel();
c.add(p2);
f.setSize(800, 500);
f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
// 主窗口中的左半边窗口即p1
public JPanel westJPanel() {
p1 = new JPanel();
b = new Box(BoxLayout.Y_AXIS);
// 设置开始按钮
startjb = new JButton("开始");
startjb.addActionListener(new MystartActionListener());
startjb.setSize(30, 20);
startjb.setBackground(Color.white);
b.add(startjb);
b.add(Box.createVerticalStrut(30));// 设置中间距离
// 设置结束按钮
endjb = new JButton("结束");
endjb.addActionListener(new MyendActionListener());
endjb.setSize(30, 20);
endjb.setBackground(Color.white);
b.add(endjb);
b.add(Box.createVerticalStrut(50));
jl[0] = new JLabel("设置红灯");
jl[0].setSize(40, 40);
jl[0].setBackground(Color.gray);
b.add(jl[0]);
b.add(Box.createVerticalStrut(10));
jt[0] = new JTextField();
jt[0].setSize(40, 20);
b.add(jt[0]);
b.add(Box.createVerticalStrut(30));
jl[1] = new JLabel("设置绿灯");
jl[1].setSize(40, 40);
jl[1].setBackground(Color.gray);
b.add(jl[1]);
b.add(Box.createVerticalStrut(10));
jt[1] = new JTextField();
jt[1].setHorizontalAlignment(JTextField.LEFT);
jt[1].setSize(40, 20);
b.add(jt[1]);
b.add(Box.createVerticalStrut(30));
jl[2] = new JLabel("黄灯时间");
jl[2].setSize(40, 40);
jl[2].setBackground(Color.gray);
b.add(jl[2]);
b.add(Box.createVerticalStrut(10));
// 显示黄灯计算后得出的时间
jl[16] = new JLabel();
jl[16].setSize(40, 20);
b.add(jl[16]);
b.add(Box.createVerticalStrut(30));
selectjb = new JButton("查询");
selectjb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new SelectGUI(f);
}
});
selectjb.setSize(30, 20);
selectjb.setBackground(Color.white);
b.add(selectjb);
b.setBackground(Color.gray);
p1.add(b);
return p1;
}
// 主窗口的右半边窗口即p2
public JPanel mainJPanel() {
p2 = new JPanel();
p2.setLayout(new BorderLayout(20, 20));
// p2的下边
p3 = dischargeJpanel(); // 车流量
p3.setBackground(Color.lightGray);
p2.add(p3, BorderLayout.SOUTH);
// p2的中间
p4 = pictureJpanel(); // 交通路口图
p2.add(p4, BorderLayout.CENTER);
// p2的上面
p5 = timerJpanel(); // 计时器
p5.setBackground(Color.lightGray);
p2.add(p5, BorderLayout.NORTH);
return p2;
}
// p2窗口中下边车流量的窗口设置即p3
public JPanel dischargeJpanel() {
p3 = new JPanel();
p3.setLayout(new GridLayout(2, 5));
jl[10] = new JLabel("确定");
jl[10].setVisible(true);
p3.add(jl[10]);
jl[11] = new JLabel("东", 0);
jl[11].setVisible(true);
p3.add(jl[11]);
jl[12] = new JLabel("南", 0);
jl[12].setVisible(true);
p3.add(jl[12]);
jl[13] = new JLabel("西", 0);
jl[13].setVisible(true);
p3.add(jl[13]);
jl[14] = new JLabel("北", 0);
jl[14].setVisible(true);
p3.add(jl[14]);
jl[15] = new JLabel("开始车辆", 0);
jl[15].setVisible(true);
p3.add(jl[15]);
jt[3] = new JTextField();
jt[3].setVisible(true);
p3.add(jt[3]);
jt[4] = new JTextField();
jt[4].setVisible(true);
p3.add(jt[4]);
jt[5] = new JTextField();
jt[5].setVisible(true);
p3.add(jt[5]);
jt[6] = new JTextField();
jt[6].setVisible(true);
p3.add(jt[6]);
return p3;
}
// p2窗口中中间交通模拟的窗口设置即p4
public JPanel pictureJpanel() {
JPanel[] jp = new JPanel[4];
p4 = new JPanel();
p4.setLayout(null);
jp[0] = new JPanel();
jp[0].setBounds(50, 0, 230, 100);
jp[0].setBackground(Color.GRAY);
jp[0].setVisible(true);
p4.add(jp[0]);
jp[1] = new JPanel();
jp[1].setBounds(420, 0, 230, 100);
jp[1].setBackground(Color.GRAY);
jp[1].setVisible(true);
p4.add(jp[1]);
jp[2] = new JPanel();
jp[2].setBounds(50, 240, 230, 100);
jp[2].setBackground(Color.GRAY);
jp[2].setVisible(true);
p4.add(jp[2]);
jp[3] = new JPanel();
jp[3].setBounds(420, 240, 230, 100);
jp[3].setBackground(Color.GRAY);
jp[3].setVisible(true);
p4.add(jp[3]);
// 第一组红绿灯
jb[0] = new JButton();
jb[0].setBounds(400, 70, 20, 10);
p4.add(jb[0]);
jb[1] = new JButton();
jb[1].setBounds(400, 80, 20, 10);
p4.add(jb[1]);
jb[2] = new JButton();
jb[2].setBounds(400, 90, 20, 10);
p4.add(jb[2]);
// 第二组红绿灯
jb[3] = new JButton();
jb[3].setBounds(250, 100, 10, 20);
p4.add(jb[3]);
jb[4] = new JButton();
jb[4].setBounds(260, 100, 10, 20);
p4.add(jb[4]);
jb[5] = new JButton();
jb[5].setBounds(270, 100, 10, 20);
p4.add(jb[5]);
// 第三组红绿灯
jb[6] = new JButton();
jb[6].setBounds(420, 220, 10, 20);
// jb[6].setBackground(Color.green);
p4.add(jb[6]);
jb[7] = new JButton();
jb[7].setBounds(430, 220, 10, 20);
p4.add(jb[7]);
jb[8] = new JButton();
jb[8].setBounds(440, 220, 10, 20);
p4.add(jb[8]);
// 第四组红绿灯
jb[9] = new JButton();
jb[9].setBounds(280, 240, 20, 10);
p4.add(jb[9]);
jb[10] = new JButton();
jb[10].setBounds(280, 250, 20, 10);
p4.add(jb[10]);
jb[11] = new JButton();
jb[11].setBounds(280, 260, 20, 10);
p4.add(jb[11]);
// 方向标记
jl[17] = new JLabel("北", 0);
jl[17].setSize(20, 15);
jl[17].setLocation(340, 0);
p4.add(jl[17]);
jl[18] = new JLabel("南", 0);
jl[18].setSize(20, 15);
jl[18].setLocation(340, 340);
p4.add(jl[18]);
jl[19] = new JLabel("西", 0);
jl[19].setSize(20, 15);
jl[19].setLocation(10, 160);
p4.add(jl[19]);
jl[20] = new JLabel("东", 0);
jl[20].setSize(20, 15);
jl[20].setLocation(670, 160);
p4.add(jl[20]);
return p4;
}
// p2窗口中上边时间窗口的设置即p5
public JPanel timerJpanel() {
p5 = new JPanel();
p5.setLayout(new GridLayout(1, 7));
jl[3] = new JLabel("时间:", 0);
jl[3].setVisible(true);
p5.add(jl[3]);
jl[4] = new JLabel(" 红灯", 0);
jl[4].setVisible(true);
p5.add(jl[4]);
jl[5] = new JLabel();
jl[5].setVisible(true);
p5.add(jl[5]);
jl[6] = new JLabel(" 绿灯", 0);
jl[6].setVisible(true);
p5.add(jl[6]);
jl[7] = new JLabel();
jl[7].setVisible(true);
p5.add(jl[7]);
jl[8] = new JLabel(" 黄灯", 0);
jl[8].setVisible(true);
p5.add(jl[8]);
jl[9] = new JLabel();
jl[9].setVisible(true);
p5.add(jl[9]);
// 红灯计时事件
timer1 = new Timer(1000, new Mytimer1ActionListener());
// 绿灯计时事件
timer2 = new Timer(1000, new ActionListener() {
ClockTime ct = new ClockTime();
public void actionPerformed(ActionEvent e) {
ct.setJl2(jl[7]);
ct.setJl3(jl[9]);
ct.setJl4(jl[16]);
ct.setT1(timer2);
ct.setT2(timer3);
ct.clock2();
}
});
// 黄灯计时事件
timer3 = new Timer(1000, new ActionListener() {
ClockTime ct = new ClockTime();
public void actionPerformed(ActionEvent e) {
ct.setJl2(jl[7]);
ct.setJl3(jl[9]);
ct.setJt2(jt[1]);
ct.setT1(timer2);
ct.setT2(timer3);
ct.clock3();
}
});
return p5;
}
public static void main(String[] args) {
new MainGUI();
}
}







