⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stuaddframe.java

📁 包含了学生管理系统的一些基本操作以及相关窗口页面实现。
💻 JAVA
字号:
package com.hb.studentmanager.ui;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import javax.swing.WindowConstants;

import oracle.sql.BLOB;

import com.hb.studentmanager.action.StuAction;
import com.hb.studentmanager.connection.ConnectionDateBase;
import com.hb.studentmanager.tools.ChooseFile;
import com.hb.studentmanager.tools.DateChooserJButton;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class StuAddFrame extends javax.swing.JDialog {
	public JLabel stuidjLabel;
	public JLabel namejLabel;
	public JTextField teljTextField;
	public ButtonGroup buttonGroup1;
	public JRadioButton womenjRadioButton;
	public JRadioButton manjRadioButton;
	public JLabel jLabel;
	public JButton submjButton;
	public JTextArea addjTextArea;
	public JTextArea beizjTextArea;
	public JScrollPane beizjScrollPane;
	public JScrollPane addjScrollPane;
	public JLabel beizjLabel;
	public JLabel addjLabel;
	public JComboBox zhengzjComboBox;
	public JLabel zhenzjLabel;
	public JButton phojButton;
	public JLabel phojLabel;
	public JComboBox classjComboBox;
	public JTextField namejTextField;
	public JTextField stuidjTextField;
	public JLabel teljLabel;
	public JLabel classjLabel;
	public JLabel birjLabel;
	public JLabel sexjLabel;
	public File file;
	public DateChooserJButton datejButton;
	StuMainFrame smf=new StuMainFrame();
	StuAction sa=new StuAction();
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
	}
	
	public StuAddFrame(StuMainFrame smf) {
		super();
		initGUI(smf);
		/**
		 * 设置面板居中显示		 */
		int width=Toolkit.getDefaultToolkit().getScreenSize().width;
		int height=Toolkit.getDefaultToolkit().getScreenSize().height;
		this.setLocation((width-450)/2, (height-470)/2);
		this.setResizable(false);//设置面板大小不可变	}
	
	private void initGUI(final StuMainFrame smf) {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("\u6dfb\u52a0\u5b66\u751f\u4fe1\u606f");
			{
				{				}
				{
					buttonGroup1 = new ButtonGroup();
				}
				stuidjLabel = new JLabel();
				getContentPane().add(stuidjLabel);
				stuidjLabel.setText("\u5b66\u53f7\uff1a");
				stuidjLabel.setBounds(14, 7, 63, 28);
			}
			{
				namejLabel = new JLabel();
				getContentPane().add(namejLabel);
				namejLabel.setText("\u59d3\u540d\uff1a");
				namejLabel.setBounds(14, 63, 63, 28);
			}
			{
				sexjLabel = new JLabel();
				getContentPane().add(sexjLabel);
				sexjLabel.setText("\u6027\u522b\uff1a");
				sexjLabel.setBounds(14, 112, 63, 28);
			}
			{
				birjLabel = new JLabel();
				getContentPane().add(birjLabel);
				birjLabel.setText("\u51fa\u751f\u65e5\u671f\uff1a");
				birjLabel.setBounds(14, 168, 70, 28);
			}
			{
				classjLabel = new JLabel();
				getContentPane().add(classjLabel);
				classjLabel.setText("\u6240\u5728\u73ed\u7ea7\uff1a");
				classjLabel.setBounds(14, 231, 70, 28);
			}
			{
				teljLabel = new JLabel();
				getContentPane().add(teljLabel);
				teljLabel.setText("\u8054\u7cfb\u7535\u8bdd\uff1a");
				teljLabel.setBounds(14, 294, 70, 28);
			}
			{
				stuidjTextField = new JTextField();
				getContentPane().add(stuidjTextField);
				stuidjTextField.setBounds(91, 7, 126, 28);
			}
			{
				namejTextField = new JTextField();
				getContentPane().add(namejTextField);
				namejTextField.setBounds(91, 63, 126, 28);
			}
			{
				DefaultComboBoxModel classjComboBoxModel = new DefaultComboBoxModel();
				sa.getClassName(classjComboBoxModel);//调用StuAction中的getClassName方法,并将结果放到classjComboBoxModel中				classjComboBox = new JComboBox();
				getContentPane().add(classjComboBox);
				classjComboBox.setModel(classjComboBoxModel);
				classjComboBox.setBounds(91, 231, 126, 28);
				classjComboBox.setSelectedIndex(1);
			}
			{
				teljTextField = new JTextField();
				getContentPane().add(teljTextField);
				teljTextField.setBounds(91, 294, 126, 28);
			}
			{
				phojLabel = new JLabel();
				getContentPane().add(phojLabel);
				phojLabel.setBounds(315, 7, 105, 119);
				phojLabel.setText("        \u663e\u793a\u7167\u7247\u5904");
				phojLabel.setSize(105, 120);
			}
			{
				phojButton = new JButton();
				getContentPane().add(phojButton);
				phojButton.setText("\u6dfb\u52a0\u7167\u7247");
				phojButton.setBounds(322, 126, 91, 28);
				phojButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						phojButtonActionPerformed(evt);
					}
				});
				smf.gettable(smf.s1,smf.s2,smf.s3,smf.s4,smf.s5,smf.s6,smf.s7);
			}
			{
				zhenzjLabel = new JLabel();
				getContentPane().add(zhenzjLabel);
				zhenzjLabel.setText("\u653f\u6cbb\u9762\u8c8c\uff1a");
				zhenzjLabel.setBounds(14, 357, 70, 28);
			}
			{
				ComboBoxModel zhengzjComboBoxModel = new DefaultComboBoxModel(
					new String[] {"团员", "党员" });
				zhengzjComboBox = new JComboBox();
				getContentPane().add(zhengzjComboBox);
				zhengzjComboBox.setModel(zhengzjComboBoxModel);
				zhengzjComboBox.setBounds(91, 357, 126, 28);
			}
			{
				addjLabel = new JLabel();
				getContentPane().add(addjLabel);
				addjLabel.setText("\u5bb6\u5ead\u4f4f\u5740\uff1a");
				addjLabel.setBounds(315, 175, 70, 28);
			}
			{
				beizjLabel = new JLabel();
				getContentPane().add(beizjLabel);
				beizjLabel.setText("\u5907\u6ce8\uff1a");
				beizjLabel.setBounds(315, 287, 63, 28);
			}
			{
				addjScrollPane = new JScrollPane();
				getContentPane().add(addjScrollPane);
				addjScrollPane.setBounds(315, 203, 105, 77);
				{
					addjTextArea = new JTextArea();
					addjScrollPane.setViewportView(addjTextArea);
					addjTextArea.setBounds(259, 259, 63, 28);
					addjTextArea.setLineWrap(true);
				}
			}
			{
				beizjScrollPane = new JScrollPane();
				getContentPane().add(beizjScrollPane);
				beizjScrollPane.setBounds(315, 315, 105, 77);
				{
					beizjTextArea = new JTextArea();
					beizjScrollPane.setViewportView(beizjTextArea);
					beizjTextArea.setLineWrap(true);
					beizjTextArea.setBounds(218, 329, 54, 42);
				}
			}
			{
				submjButton = new JButton();
				getContentPane().add(submjButton);
				submjButton.setText("\u63d0\u4ea4");
				submjButton.setBounds(329, 399, 70, 28);
				submjButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						submjButtonActionPerformed(evt,smf);
					}
				});
			}
			{
				jLabel = new JLabel();
				getContentPane().add(jLabel);
				jLabel.setBounds(14, 35, 266, 28);
				jLabel.setText("(*\u5b66\u53f7\u5fc5\u987b\u586b\u5199\uff0c\u5e76\u4e14\u4ee5hb0001\u81f3hb9999)");
			}
			{
				manjRadioButton = new JRadioButton();
				getContentPane().add(manjRadioButton);
				manjRadioButton.setText("\u7537");
				manjRadioButton.setBounds(91, 112, 63, 28);
				buttonGroup1.add(manjRadioButton);
				manjRadioButton.setSelected(true);
			}
			{
				womenjRadioButton = new JRadioButton();
				getContentPane().add(womenjRadioButton);
				womenjRadioButton.setText("\u5973");
				womenjRadioButton.setBounds(154, 112, 63, 28);
				buttonGroup1.add(womenjRadioButton);
			}
			{
				datejButton = new DateChooserJButton();
				getContentPane().add(datejButton);
				datejButton.setBounds(91, 168, 126, 28);
			}
			pack();
			this.setSize(450, 470);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void phojButtonActionPerformed(ActionEvent evt) {
		ChooseFile cF=new ChooseFile();
		file=cF.chooseFile();
		if(file!=null){
			ImageIcon icon = new ImageIcon(file.getAbsolutePath());
			phojLabel.setText("");
			phojLabel.setIcon(icon);
		}
	}
	
	private void submjButtonActionPerformed(ActionEvent evt,StuMainFrame smf) {
		if(stuidjTextField.getText().equals("")){
			JOptionPane.showMessageDialog(this, "学号必须填写");
		}
		else
		{
			if(namejTextField.getText().getBytes().length>20||teljTextField.getText().getBytes().length>20||
					addjTextArea.getText().getBytes().length>100||beizjTextArea.getText().getBytes().length>100){
				JOptionPane.showMessageDialog(this, "输入字符太长");
			}
			else{
			String s=this.stuidjTextField.getText().trim();
			if(s.length()==6)
			{
			String s1=s.substring(0, 2);
			String s2=s.substring(2, 6);
			if(s1.equals("hb")&&s2.matches("\\d{4}"))
			{
				if(sa.compare(s))
				{
					JOptionPane.showMessageDialog(this,"此学号已存在,请重新输入!");
				}
				else
				{
					ko();
				}
			}
			else
			{
				JOptionPane.showMessageDialog(this, "学号命名不符合规范,请重新输入!");
			}
			}
			else
			{
				JOptionPane.showMessageDialog(this, "学号命名不符合规范,请重新输入!");
			}
		}
	}
	}
	public void ko(){
		try{
		    int i=JOptionPane.showConfirmDialog(this, "是否确定添加","警告!",JOptionPane.OK_OPTION);
		    if(i==1)
		    {
		    	return;
		    }
		    sa.addStudent(this);
		    smf.s1="";smf.s2="";smf.s3="";smf.s4="";smf.s5="";smf.s6="";smf.s7="";
			smf.gettable(smf.s1,smf.s2,smf.s3,smf.s4,smf.s5,smf.s6,smf.s7);
			this.setVisible(false);	
			}catch(Exception e)
			{
				e.printStackTrace();
			}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -