Java项目:考试系统Java基础Gui(java+Gui)

源码获取:博客首页 "资源" 里下载!

功能简介:

所属课程、题目内容、题目选项、题目答案、题目等级、学生管理、试卷管理、题目管理、时间控制

 

 

 

服务页面:

public class ServerClient extends javax.swing.JFrame {

	/*
	 * // 注入TitleManage private TitleManage titleManage = new TitleManageImp();
	 * // 注入UserManage private UserManage userManage = new UserManageImp();
	 */
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** Creates new form ServerClient */
	public ServerClient() {
		initComponents();
		this.setVisible(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// 
	private void initComponents() {

		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				int var = JOptionPane.showConfirmDialog(ServerClient.this,
						"确定离开吗?");
				if (var == JOptionPane.YES_OPTION) {
					System.exit(0);
				}
			}
		});

		jMenuBar1 = new javax.swing.JMenuBar();
		jMenu1 = new javax.swing.JMenu();
		jMenuItem1 = new javax.swing.JMenuItem();
		jMenuItem2 = new javax.swing.JMenuItem();
		jMenuItem3 = new javax.swing.JMenuItem();
		jMenuItem4 = new javax.swing.JMenuItem();
		jMenu2 = new javax.swing.JMenu();

		jMenu1.setText("\u83dc\u5355");

		jMenuItem1.setText("\u9898\u76ee\u7ba1\u7406");
		jMenu1.add(jMenuItem1);

		// 增加对题目管理的事件
		jMenuItem1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				new TitleManageFrame();

			}
		});
		jMenuItem2.setText("\u5b66\u751f\u7ba1\u7406");
		jMenu1.add(jMenuItem2);

		jMenuItem3.setText("试卷管理");
		jMenu1.add(jMenuItem3);

		jMenuItem3.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				new CreatePaper();

			}
		});
		jMenuItem4.setText("退出");
		jMenu1.add(jMenuItem4);

		jMenuItem4.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});

		// 添加学生管理的事件
		jMenuItem2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new StudentManageFrame();
			}
		});
		jMenuBar1.add(jMenu1);

		jMenu2.setText("帮助");
		jMenuBar1.add(jMenu2);

		setJMenuBar(jMenuBar1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		{
			jLabel1 = new JLabel();
		}

		layout.setVerticalGroup(layout.createSequentialGroup()
				.addContainerGap().addComponent(jLabel1, 0, 398,
						Short.MAX_VALUE));
		layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(
				jLabel1, 0, 665, Short.MAX_VALUE));
		jLabel1.setIcon(new ImageIcon(getClass().getResource("exam1.jpg")));
		pack();
		// 置中
		this.setLocationRelativeTo(null);
		// 固定大小
		setResizable(false);
	}// 

	// GEN-END:initComponents

	/**
	 * @param args
	 *            the command line arguments
	 */
	

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JMenu jMenu1;
	private javax.swing.JMenu jMenu2;
	private javax.swing.JMenuBar jMenuBar1;
	private JLabel jLabel1;
	private javax.swing.JMenuItem jMenuItem1;
	private javax.swing.JMenuItem jMenuItem2;
	private javax.swing.JMenuItem jMenuItem3;
	private javax.swing.JMenuItem jMenuItem4;
	// End of variables declaration//GEN-END:variables

}

学生页面服务:

public class UpdateStudentFrame extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;

	/**
	 * Auto-generated main method to display this JFrame
	 */

	private JButton jButton1;
	private JLabel jLabel2;
	private JTextField jTextField4;
	private JTextField jTextField3;
	private JTextField jTextField2;
	private JTextField jTextField1;
	private JButton jButton2;
	private JLabel jLabel1;
	private JLabel jLabel10;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JPanel jPanel1;
	private User user;
	private int paper;

	/**
	 * 
	 */

	// 注入UserManage
	private static UserManage userManage = new UserManageImp();

	public UpdateStudentFrame(User user, int paper2) {
		super();
		this.user = user;
		this.paper = paper2;
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(0, -100, 562, 458);
				jPanel1.setLayout(null);
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("\u9898\u76ee\u5185\u5bb9");
					jLabel1.setBounds(67, 48, 91, 33);
				}
				{
					jLabel7 = new JLabel();
					jPanel1.add(jLabel7);
					jLabel7.setText("\u5b66\u751f\u59d3\u540d");
					jLabel7.setBounds(135, 195, 68, 17);
				}
				{
					jButton1 = new JButton();
					jPanel1.add(jButton1);
					jButton1.setText("\u4fee\u6539");
					jButton1.setBounds(226, 361, 67, 24);
				}
				{
					jButton2 = new JButton();
					jPanel1.add(jButton2);
					jButton2.setText("\u6e05\u7a7a");
					jButton2.setBounds(351, 361, 68, 24);
				}
				{
					jLabel8 = new JLabel();
					jPanel1.add(jLabel8);
					jLabel8.setText("\u5b66\u751f\u5bc6\u7801");
					jLabel8.setBounds(135, 253, 68, 17);
				}
				{
					jLabel10 = new JLabel();
					jPanel1.add(jLabel10);
					jLabel10.setText("\u8bd5\u5377\u7f16\u53f7");
					jLabel10.setBounds(135, 307, 68, 17);
					jLabel10.setOpaque(true);
				}
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("\u5b66\u751f\u7f16\u53f7");
					jLabel2.setBounds(135, 123, 91, 33);
				}
				{
					jTextField1 = new JTextField();
					jPanel1.add(jTextField1);
					jTextField1.setText(user.getUid() + "");
					jTextField1.setEditable(false);
					jTextField1.setBounds(238, 128, 181, 24);
				}
				{
					jTextField2 = new JTextField();
					jPanel1.add(jTextField2);
					jTextField2.setText(user.getName());
					jTextField2.setEditable(false);
					jTextField2.setBounds(238, 192, 181, 24);
				}
				{
					jTextField3 = new JTextField();
					jPanel1.add(jTextField3);
					jTextField3.setText(user.getPassword());
					jTextField3.setBounds(238, 250, 181, 23);
				}
				{
					jTextField4 = new JTextField();
					jPanel1.add(jTextField4);
					jTextField4.setText(paper + "");
					jTextField4.setEditable(false);
					jTextField4.setBounds(238, 304, 181, 23);
				}
			}
			pack();
			this.setSize(552, 391);

			setLocationRelativeTo(null);
			setVisible(true);
			jTextField1.setEditable(false);
			jTextField4.setEditable(false);

			// 修改密码事件
			jButton1.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {

					String name = jTextField2.getText();
					String password = jTextField3.getText();
					User user1 = new User();
					user1.setUid(user.getUid());
					user1.setName(name);
					user1.setPassword(password);
					Paper paper1 = new Paper();
					if (paper == 0) {
						paper1 = null;
						userManage.update(user1);
					} else {
						paper1.setPid(paper);
						user1.setPaper(paper1);

						userManage.update(user1);
					}
					JOptionPane
							.showMessageDialog(UpdateStudentFrame.this, "update success!!!");
				}
			});
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}

		jButton2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				jTextField3.setText("");

			}
		});

	}

}

添加标题页面:

public class AddTitleFrame extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	

	private JButton jButton1;
	private JButton jButton2;
	private JLabel jLabel1;
	private JLabel jLabel10;
	private JLabel jLabel11;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel12;
	private JComboBox jComboBox3;
	private JComboBox jComboBox2;
	private JComboBox jComboBox1;
	private JTextField jTextField3;
	private JLabel jLabel6;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JLabel jLabel9;
	private JPanel jPanel1;
	private JTextArea jTextArea1;
	private JTextField jTextField1;
	private JTextField jTextField2;
	private JTextField jTextField4;
	private JComboBox jComboBox4;

	/**
	 * 
	 */

	// 注入Service
	private TitleManage titleManage = new TitleManageImp();

	public AddTitleFrame() {
		super();
		initGUI();
	}

	public JTextField getJTextField2() {
		return jTextField2;
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(0, 0, 723, 488);
				jPanel1.setLayout(null);
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("\u9898\u76ee\u5185\u5bb9");
					jLabel1.setBounds(67, 48, 91, 33);
				}
				{
					jTextArea1 = new JTextArea();
					jPanel1.add(jTextArea1);
					jTextArea1.setBounds(176, 22, 391, 86);
				}
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("A");
					jLabel2.setBounds(147, 150, 23, 17);
				}
				{
					jTextField1 = new JTextField();
					jPanel1.add(jTextField1);
					jTextField1.setBounds(195, 147, 131, 24);
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("B");
					jLabel3.setBounds(392, 150, 26, 17);
				}
				{
					jTextField2 = new JTextField();
					jPanel1.add(getJTextField2());
					jTextField2.setBounds(436, 147, 131, 24);
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("C");
					jLabel4.setBounds(147, 179, 14, 16);
				}
				{
					jLabel5 = new JLabel();
					jPanel1.add(jLabel5);
					jLabel5.setText("D");
					jLabel5.setBounds(392, 181, 20, 17);
				}
				{
					jLabel6 = new JLabel();
					jPanel1.add(jLabel6);
					jLabel6.setText("\u9898\u76ee\u9009\u9879");
					jLabel6.setBounds(67, 150, 59, 17);
				}
				{
					jLabel7 = new JLabel();
					jPanel1.add(jLabel7);
					jLabel7.setText("\u9898\u76ee\u7b54\u6848");
					jLabel7.setBounds(67, 229, 68, 17);
				}
				{
					jButton1 = new JButton();
					jPanel1.add(jButton1);
					jButton1.setText("\u589e\u52a0");
					jButton1.setBounds(188, 402, 67, 24);
				}
				{
					jButton2 = new JButton();
					jPanel1.add(jButton2);
					jButton2.setText("\u6e05\u7a7a");
					jButton2.setBounds(365, 402, 68, 24);
				}
				{
					jTextField4 = new JTextField();
					jPanel1.add(jTextField4);
					jTextField4.setBounds(436, 177, 131, 21);
				}
				{
					jLabel8 = new JLabel();
					jPanel1.add(jLabel8);
					jLabel8.setText("\u9898\u76ee\u96be\u5ea6");
					jLabel8.setBounds(67, 274, 68, 17);
				}
				{
					jLabel9 = new JLabel();
					jPanel1.add(jLabel9);
					jLabel9.setText("1---5\u4e4b\u95f4");
					jLabel9.setBounds(267, 277, 137, 17);
				}
				{
					jLabel10 = new JLabel();
					jPanel1.add(jLabel10);
					jLabel10.setText("\u9898\u76ee\u5206\u6570");
					jLabel10.setBounds(67, 327, 68, 17);
					jLabel10.setOpaque(true);
				}
				{
					jLabel11 = new JLabel();
					jPanel1.add(jLabel11);
					jLabel11.setText("0---100\u4e4b\u95f4");
					jLabel11.setBounds(267, 327, 137, 17);
					jLabel11.setOpaque(true);
				}
				{
					jTextField3 = new JTextField();
					jPanel1.add(jTextField3);
					jTextField3.setBounds(195, 176, 131, 24);
				}
				{
					ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
							new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
					jComboBox1 = new JComboBox();
					jPanel1.add(jComboBox1);
					jComboBox1.setModel(jComboBox1Model);
					jComboBox1.setBounds(176, 270, 73, 24);
				}
				{
					ComboBoxModel jComboBox2Model = new DefaultComboBoxModel(
							new String[] { "A", "B", "C", "D" });
					jComboBox2 = new JComboBox();
					jPanel1.add(jComboBox2);
					jComboBox2.setModel(jComboBox2Model);
					jComboBox2.setBounds(176, 225, 73, 24);
				}
				{

					ComboBoxModel jComboBox3Model = new DefaultComboBoxModel(
							new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
									12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
									23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
									34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
									45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
									56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
									67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
									78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
									89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
									100 });
					jComboBox3 = new JComboBox();
					jComboBox3.setMaximumRowCount(5);
					jPanel1.add(jComboBox3);
					jComboBox3.setModel(jComboBox3Model);
					jComboBox3.setBounds(176, 323, 73, 24);
				}
				{
					jLabel12 = new JLabel();
					jPanel1.add(jLabel12);
					jLabel12.setText("\u6240\u5c5e\u8bfe\u7a0b");
					jLabel12.setBounds(67, 116, 59, 17);
				}
				{
					ComboBoxModel jComboBox4Model = 
						new DefaultComboBoxModel(
								new String[] {"JAVA SE", "MySql", "离散数学", "操作系统",
										"计算机网络", "编译原理", "C语言", "C++", "汇编语言"});
					jComboBox4 = new JComboBox();
					jPanel1.add(jComboBox4);
					jComboBox4.setModel(jComboBox4Model);
					jComboBox4.setBounds(180, 117, 107, 24);
				}
			}
			pack();
			this.setSize(734, 526);

			setLocationRelativeTo(null);
			setVisible(true);

			// 增加题目事件
			jButton1.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					String question = jTextArea1.getText();
					// System.out.println(question);
					String option = "A:" + jTextField1.getText() + ",B:"
							+ jTextField2.getText() + ",C:"
							+ jTextField3.getText() + ",D:"
							+ jTextField4.getText();
					String key = (String) jComboBox2.getSelectedItem();
					int level = (Integer) (jComboBox1.getSelectedItem());
					int score = (Integer) jComboBox3.getSelectedItem();
					String course = (String) jComboBox4.getSelectedItem();
					System.out.println(level);

					Title title = new Title();
					// title.setTid(1);
					title.setQuestion(question);
					title.setOption(option);
					title.setKey(key);
					title.setLevel(level);
					title.setScore(score);
					title.setCourse(course);

					titleManage.save(title);
					JOptionPane.showMessageDialog(AddTitleFrame.this, "add success!!!");
				}
			});
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}

		jButton2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				jTextArea1.setText("");
				jTextField1.setText("");
				jTextField2.setText("");
				jTextField3.setText("");
				jTextField4.setText("");
				jComboBox1.setSelectedIndex(0);
				jComboBox2.setSelectedIndex(2);
				jComboBox3.setSelectedIndex(4);

			}
		});

	}

}

源码获取:博客首页 "资源" 里下载!

你可能感兴趣的:(Java毕业设计项目实战篇,java,Gui)