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

📄 teamainframe.java

📁 包含了学生管理系统的一些基本操作以及相关窗口页面实现。
💻 JAVA
字号:
package com.hb.studentmanager.ui;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.hb.studentmanager.action.ClaAction;
import com.hb.studentmanager.action.StuAction;
import com.hb.studentmanager.action.TeaAction;

/**
* 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 TeaMainFrame extends javax.swing.JFrame {
	private JPanel teaPanel1;
	private JButton tearebackButton1;
	private JButton firstButton1;
	private JButton teadelButton1;
	private JButton teaupdateButton1;
	private JButton teainsertButton1;
	private JButton teaselButton1;
	private JTextField teaaddTextField1;
	private JLabel teaaddLabel1;
	private JComboBox teadate2ComboBox1;
	private JLabel ssLabel1;
	private JComboBox teadateComboBox1;
	private JLabel teadateLabel1;
	private JComboBox teasexComboBox1;
	private JLabel teasexLabel1;
	private JPanel jPanel1;
	private JTextField teanameTextField1;
	private JLabel teanameLabel1;
	private JTextField teaidTextField1;
	private JLabel idLabel1;
	private JButton lastButton1;
	private JButton downButton1;
	private JTable teaTable1;
	private JButton upButton1;
	private JTabbedPane teaTabbedPane1;
	private JScrollPane teaScrollPane1;
	private DefaultTableModel teaTable1Model;
	private int page=1;
	TeaAction ta=new TeaAction();
	public String s0="",s1="",s2="",s3="",s4="",s5="";

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		TeaMainFrame inst = new TeaMainFrame();
		inst.setVisible(true);
		
	}
	
	public TeaMainFrame() {
		super();
		initGUI();
		int width=Toolkit.getDefaultToolkit().getScreenSize().width;
		int height=Toolkit.getDefaultToolkit().getScreenSize().height;
		this.setLocation((width-630)/2, (height-450)/2);
		this.setResizable(false);
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("\u6559\u5e08\u4fe1\u606f\u7ba1\u7406\u9875\u9762");
			getContentPane().setLayout(null);
			{
				teaPanel1 = new JPanel();
				getContentPane().add(teaPanel1);
				teaPanel1.setBounds(0, 0, 623, 427);
				teaPanel1.setLayout(null);
				{
					teaScrollPane1 = new JScrollPane();
					teaPanel1.add(teaScrollPane1);
					teaScrollPane1.setBounds(0, 0, 623, 98);
					{
					    gettable(s0,s1,s2,s3,s4,s5);
					}
				}
				{
					teaTabbedPane1 = new JTabbedPane();
					teaPanel1.add(teaTabbedPane1);
					teaTabbedPane1.setBounds(0, 161, 623, 210);
					{
						jPanel1 = new JPanel();
						teaTabbedPane1.addTab("查询条件", null, jPanel1, null);
						jPanel1.setLayout(null);
						{
							idLabel1 = new JLabel();
							jPanel1.add(idLabel1);
							idLabel1.setText("\u6559\u5e08\u7f16\u53f7:");
							idLabel1.setBounds(7, 14, 63, 28);
						}
						{
							teaidTextField1 = new JTextField();
							jPanel1.add(teaidTextField1);
							teaidTextField1.setBounds(84, 14, 126, 28);
						}
						{
							teanameLabel1 = new JLabel();
							jPanel1.add(teanameLabel1);
							teanameLabel1.setText("\u59d3\u540d\uff1a");
							teanameLabel1.setBounds(7, 70, 63, 28);
						}
						{
							teanameTextField1 = new JTextField();
							jPanel1.add(teanameTextField1);
							teanameTextField1.setBounds(84, 70, 126, 28);
						}
						{
							teasexLabel1 = new JLabel();
							jPanel1.add(teasexLabel1);
							teasexLabel1.setText("\u6027\u522b\uff1a");
							teasexLabel1.setBounds(7, 126, 63, 28);
						}
						{
							ComboBoxModel teasexComboBox1Model = new DefaultComboBoxModel();
							teasexComboBox1 = new JComboBox();
							jPanel1.add(teasexComboBox1);
							teasexComboBox1.setModel(teasexComboBox1Model);
							teasexComboBox1.setBounds(84, 126, 126, 28);
							teasexComboBox1.insertItemAt(null, 0);
							teasexComboBox1.addItem("男");
							teasexComboBox1.addItem("女");
						}
						{
							teadateLabel1 = new JLabel();
							jPanel1.add(teadateLabel1);
							teadateLabel1.setText("\u51fa\u751f\u65e5\u671f:");
							teadateLabel1.setBounds(266, 14, 63, 28);
						}
						{
							ComboBoxModel teadateComboBox1Model = new DefaultComboBoxModel();
							teadateComboBox1 = new JComboBox();
							jPanel1.add(teadateComboBox1);
							teadateComboBox1.setModel(teadateComboBox1Model);
							teadateComboBox1.setBounds(343, 14, 91, 28);
							teadateComboBox1.insertItemAt(null, 0);
							for(int i=1950;i<2010;i++)
							{
								teadateComboBox1.addItem(String.valueOf(i));
							}
							teadateComboBox1.addItem(null);
						}
						{
							ssLabel1 = new JLabel();
							jPanel1.add(ssLabel1);
							ssLabel1.setText("\u81f3");
							ssLabel1.setBounds(462, 14, 35, 28);
						}
						{
							ComboBoxModel teadate2ComboBox1Model = new DefaultComboBoxModel();
							teadate2ComboBox1 = new JComboBox();
							jPanel1.add(teadate2ComboBox1);
							teadate2ComboBox1.setModel(teadate2ComboBox1Model);
							teadate2ComboBox1.setBounds(504, 14, 91, 28);
							teadate2ComboBox1.insertItemAt(null, 0);
							for(int i=1950;i<2010;i++)
							{
								teadate2ComboBox1.addItem(String.valueOf(i));
							}
							teadate2ComboBox1.addItem(null);
						}
						{
							teaaddLabel1 = new JLabel();
							jPanel1.add(teaaddLabel1);
							teaaddLabel1.setText("\u5bb6\u5ead\u4f4f\u5740:");
							teaaddLabel1.setBounds(266, 70, 63, 28);
						}
						{
							teaaddTextField1 = new JTextField();
							jPanel1.add(teaaddTextField1);
							teaaddTextField1.setBounds(343, 70, 252, 28);
						}
						{
							teaselButton1 = new JButton();
							jPanel1.add(teaselButton1);
							teaselButton1.setText("\u67e5\u8be2");
							teaselButton1.setBounds(504, 126, 84, 28);
							teaselButton1
								.addActionListener(new ActionListener() {
								public void actionPerformed(ActionEvent evt) {
									teaselButton1ActionPerformed(evt);
								}
								});
						}
					}
				}
				{
					firstButton1 = new JButton();
					teaPanel1.add(firstButton1);
					firstButton1.setText("\u9996\u9875");
					firstButton1.setBounds(28, 119, 77, 28);
					firstButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							firstButton1ActionPerformed(evt);
						}
					});
				}
				{
					upButton1 = new JButton();
					teaPanel1.add(upButton1);
					upButton1.setText("\u4e0a\u4e00\u9875");
					upButton1.setBounds(168, 119, 84, 28);
					upButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							upButton1ActionPerformed(evt);
						}
					});
				}
				{
					downButton1 = new JButton();
					teaPanel1.add(downButton1);
					downButton1.setText("\u4e0b\u4e00\u9875");
					downButton1.setBounds(343, 119, 77, 28);
					downButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							downButton1ActionPerformed(evt);
						}
					});
				}
				{
					lastButton1 = new JButton();
					teaPanel1.add(lastButton1);
					lastButton1.setText("\u5c3e\u9875");
					lastButton1.setBounds(511, 119, 77, 28);
					lastButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							lastButton1ActionPerformed(evt);
						}
					});
				}
				{
					teainsertButton1 = new JButton();
					teaPanel1.add(teainsertButton1);
					teainsertButton1.setText("\u6dfb\u52a0");
					teainsertButton1.setBounds(21, 385, 77, 28);
					teainsertButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							teainsertButton1ActionPerformed(evt);
						}
					});
				}
				{
					teaupdateButton1 = new JButton();
					teaPanel1.add(teaupdateButton1);
					teaupdateButton1.setText("\u4fee\u6539");
					teaupdateButton1.setBounds(147, 385, 77, 28);
					teaupdateButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							teaupdateButton1ActionPerformed(evt);
						}
					});
				}
				{
					teadelButton1 = new JButton();
					teaPanel1.add(teadelButton1);
					teadelButton1.setText("\u5220\u9664");
					teadelButton1.setBounds(273, 385, 77, 28);
					teadelButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							teadelButton1ActionPerformed(evt);
						}
					});
				}
				{
					tearebackButton1 = new JButton();
					teaPanel1.add(tearebackButton1);
					tearebackButton1.setText("\u8fd4\u56de");
					tearebackButton1.setBounds(399, 385, 77, 28);
					tearebackButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							tearebackButton1ActionPerformed(evt);
						}
					});
				}
			}
			pack();
			this.setSize(630, 450);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void tearebackButton1ActionPerformed(ActionEvent evt) {
		StudentManagerFrame smt =new StudentManagerFrame();
		this.setVisible(false);
		smt.setVisible(true);
	}
	
	private void teainsertButton1ActionPerformed(ActionEvent evt) {
		TeaAddFrame taf=new TeaAddFrame(this);
		taf.setModal(true);
		taf.setVisible(true);
	}
	
	private void teaupdateButton1ActionPerformed(ActionEvent evt) {
		try{
		 Object n =teaTable1.getValueAt(teaTable1.getSelectedRow(), 0);
		 String teaid=n.toString();
		 TeaAction ta= new TeaAction();
		 if(teaid.equals(""))
		 {
			 JOptionPane.showMessageDialog(this, "请先选择要修改的行");
		 }
		 else
		 {
		  TeaUpdateFrame cuf=new TeaUpdateFrame(this);
		  ta.setValue(teaid, cuf);
		  cuf.setModal(true);
		  cuf.setVisible(true);
		 }
		 }catch(Exception e)
		 {
			 JOptionPane.showMessageDialog(this,"请先选择要修改的行" );
		 }
	}
	
	private void teadelButton1ActionPerformed(ActionEvent evt) {
		try
		{
			Object n=teaTable1.getValueAt(teaTable1.getSelectedRow(),0 );
			String teaid=n.toString();
			TeaAction ta=new TeaAction();
			if(teaid.equals(""))
			{
				JOptionPane.showMessageDialog(this, "请选择要删除的行");
			}
			else
			{
				int control=JOptionPane.showConfirmDialog(this, "真的要删除吗?","警告!",JOptionPane.OK_OPTION);
				if(JOptionPane.OK_OPTION==control)
				{
					ta.delete(teaid);
					gettable(s0,s1,s2,s3,s4,s5);
				}	
			}
		}catch(Exception e)
		{
			JOptionPane.showMessageDialog(this, "请选择要删除的行!");
		}
	}
	public void gettable(String s0,String s1,String s2,String s3,String s4,String s5)
	{
		teaTable1Model = new DefaultTableModel();
	    teaTable1 = new JTable();
	    teaTable1Model.addColumn("教师编号");
	    teaTable1Model.addColumn("姓名");
	    teaTable1Model.addColumn("性别");
	    teaTable1Model.addColumn("出生日期");
	    teaTable1Model.addColumn("家庭住址");
		teaScrollPane1.setViewportView(teaTable1);
		TeaAction ta=new TeaAction();
		ta.select(s0,s1,s2,s3,s4,s5,teaTable1Model,page);
		teaTable1.setModel(teaTable1Model);
		teaTable1.setPreferredSize(new java.awt.Dimension(602, 77));
	}
	
	private void firstButton1ActionPerformed(ActionEvent evt) {
		page=1;
		gettable(s0,s1,s2,s3,s4,s5);
	}
	
	private void upButton1ActionPerformed(ActionEvent evt) {
		if(page!=1)
		{
			page=page-1;
			gettable(s0,s1,s2,s3,s4,s5);
		}
		else
		{
     		JOptionPane.showMessageDialog(this, "已经是首页了!!!");
		}
	}
	
	private void downButton1ActionPerformed(ActionEvent evt) {
		TeaAction ta=new TeaAction();
		if(page!=ta.page(s0,s1,s2,s3,s4,s5))
		{
			page=page+1;
			gettable(s0,s1,s2,s3,s4,s5);
		}
		else
		{
			JOptionPane.showMessageDialog(this, "已经是尾页了!!!");
		}
	}
	
	private void lastButton1ActionPerformed(ActionEvent evt) {
		TeaAction ta=new TeaAction();
		page=ta.page(s0,s1,s2,s3,s4,s5);
		gettable(s0,s1,s2,s3,s4,s5);
	}
	
		
	
	private void teaselButton1ActionPerformed(ActionEvent evt) {
		page=1;
		if(this.teaidTextField1.getText().equals("")&&this.teasexComboBox1.getSelectedItem()==null&&this.teanameTextField1.getText().equals("")&&this.teadateComboBox1.getSelectedItem()==null&&this.teadate2ComboBox1.getSelectedItem()==null&&this.teaaddTextField1.getText().equals(""))
		{
			JOptionPane.showMessageDialog(this, "请至少输入一个查询条件!");
		}
		else
		{
			
			int s6,s7;
			    s0=this.teaidTextField1.getText().trim();
				s1=this.teanameTextField1.getText().trim();
				s3=this.teaaddTextField1.getText().trim();	
				if(compare(s0)||compare(s1)||compare(s3))
				{
					JOptionPane.showMessageDialog(this, "不可输入通配符!!");
				}
				else
				{
				if(this.teasexComboBox1.getSelectedItem()!=null)
				{
				s2=this.teasexComboBox1.getSelectedItem().toString();
				}
				else
				{
					s2="";
				}										
				if(this.teadateComboBox1.getSelectedItem()!=null)
				{
					s4=this.teadateComboBox1.getSelectedItem().toString()+"-1-1";
				}
				else
				{
					s4="1950-1-1";
				}
	            if(this.teadate2ComboBox1.getSelectedItem()!=null)
	            {
	            	s5=this.teadate2ComboBox1.getSelectedItem().toString()+"-1-1";
	            }
	            else
	            {
	            	s5="2010-1-1";
	            }
	            s6=Integer.parseInt(s4.substring(0, 4));
	            s7=Integer.parseInt(s5.substring(0, 4));
	            if(s6>s7)
	            {
	            	JOptionPane.showMessageDialog(this, "年龄段的输入不合规范!");
	            }
	            else
	            {
				gettable(s0,s1,s2,s3,s4,s5);
			
			
	            }
				}
		}
	}
	public boolean compare(String s)
	{
		boolean flag=false;
		if(s.indexOf("'")!=-1||s.indexOf("_")!=-1||s.indexOf("%")!=-1||s.indexOf("?")!=-1)
		{
			flag=true;
		}
		return flag;
	}	
}

⌨️ 快捷键说明

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