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

📄 peoplequeryframe1.java

📁 学生信息管理系统
💻 JAVA
字号:
package com.sccp.StudentMS.baseFrame;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.sccp.StudentMS.DBtools.DBtool;
import com.swtdesigner.SwingResourceManager;

public class PeopleQueryFrame1 extends JFrame {

	private ButtonGroup buttonGroup = new ButtonGroup();
	public  JTextField t;
	private JLabel label;
	private String type;
	private String infoFrameType="a";
	ResultSet rs,rs1;
	String sql;
	DBtool db=new DBtool();
	
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			PeopleQueryFrame1 frame = new PeopleQueryFrame1();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public PeopleQueryFrame1() {
		super();
		setResizable(false);
		setTitle("人员查询");
		setBounds(100, 100, 500, 194);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		getContentPane().add(panel, BorderLayout.CENTER);

		label = new JLabel();
		label.setText("请选择查询方式:");
		label.setBounds(58, 26, 171, 15);
		panel.add(label);

		 t = new JTextField();
		t.setBounds(58, 69, 140, 20);
		t.setEnabled(false);
		panel.add(t);
		 

		final JRadioButton radioButton = new JRadioButton();
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				t.setEnabled(true);
				label.setText("请输入要查询人员的姓名:");				 
				setSearchType("name");
				
			}
		});
		buttonGroup.add(radioButton);
		radioButton.setText("按姓名");
		radioButton.setBounds(58, 113, 100, 23);
		panel.add(radioButton);

		final JRadioButton radioButton_1 = new JRadioButton();
		radioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				label.setText("请输入要查询人员的学号:");
				
				t.setEnabled(true);
				setSearchType("id");
			}
		});
		buttonGroup.add(radioButton_1);
		radioButton_1.setText("按学号");
		radioButton_1.setBounds(195, 113, 100, 23);
		panel.add(radioButton_1);

		final JRadioButton radioButton_2 = new JRadioButton();
		radioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				label.setText("请输入要查询人员的班级:");
				t.setEnabled(true);
				setSearchType("class");
			}
		});
		buttonGroup.add(radioButton_2);
		radioButton_2.setText("按班级");
		radioButton_2.setBounds(316, 113, 100, 23);
		panel.add(radioButton_2);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				if(t.getText().equals(""))
				{
					JOptionPane.showMessageDialog(null,"查询值不能为空!" );
				}
				else
				{
					sql="select * from studentInfo";
					if(type.equals("name"))
					{
						sql=sql+" where Name= '"+t.getText()+ "'";
						
					}else if(type.equals("id"))
					{
						sql=sql+" where ID='"+t.getText()+"'";
					}else if(type.equals("class"))
					{
						sql=sql+" where Class= '"+t.getText()+"'";
					}
					rs=db.getResult(sql);
					rs1=db.getResult(sql);
					 
					try {
						 
						if(rs.next())
						{
							if(!(rs.next()))
							{  
								showDifferentInfoFrame();
								PeopleQueryFrame1.this.dispose();
							}else
							{                       
								tableFrameShow();
								PeopleQueryFrame1.this.dispose();
							}
						}else
						{
							JOptionPane.showMessageDialog(null,"Sorry,无此人!");
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
				}
			}
		});
		button.setText("确定");
		button.setBounds(361, 22, 75, 23);
		panel.add(button);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				PeopleQueryFrame1.this.dispose();
			}
		});
		button_1.setText("取消");
		button_1.setBounds(361, 67, 75, 23);
		panel.add(button_1);

		final JLabel label_3 = new JLabel();
		panel.add(label_3);
		label_3.setIcon(SwingResourceManager.getIcon(PeopleQueryFrame1.class, "/images/cool5.gif"));
		label_3.setText(" ");
		label_3.setBounds(221, 22, 47, 50);

		final JLabel label_1 = new JLabel();
		label_1.setIcon(SwingResourceManager.getIcon(PeopleQueryFrame1.class, "/images/发.JPG"));
		label_1.setText(" ");
		label_1.setBounds(0, 0, 492, 178);
		panel.add(label_1);
		//
	}
	public void setLabelText(String content)
	{
		label.setText(content);
	}
    public void setSearchType(String i)
    {
    	type=i;
    }
    public void setInfoFrameType(String j)
    {
    	infoFrameType=j;
    }
    public void tableFrameShow()
    {
    	StudentInfoTableFrame sitf=new StudentInfoTableFrame();
    	sitf.showTableStudentInfo(rs1);
    	sitf.setVisible(true);
    	sitf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }
    public void setStudentInfoFrameContent(StudentInfoFrame sif)
    {
    	try {rs1.next();
			sif.id.setText(rs1.getString("ID"));
			sif.name.setText(rs1.getString("Name"));
			sif.sex.setText(rs1.getString("Sex"));
			sif.home.setText(rs1.getString("Home"));
			sif.cName.setText(rs1.getString("Class"));
			sif.ethnic.setText(rs1.getString("Ethnic"));
			sif.birth.setText(rs1.getString("Birth"));
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void showDifferentInfoFrame()
    {
    	if(infoFrameType.equals("modify"))
    	{
          setStudentInfoFrameContent(MainFrame.msif);
          MainFrame.msif.setTextAbled(false);
          MainFrame.msif.setVisible(true);
          MainFrame.msif.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          MainFrame.msif.setButton(true, true, true, false, false);
          
    	} else if(infoFrameType.equals("delete"))
    		{
            setStudentInfoFrameContent(MainFrame.dsif);
            MainFrame.dsif.setTextAbled(false);
            MainFrame.dsif.setVisible(true);
            MainFrame.dsif.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            MainFrame.dsif.setButton(true, true, true, false, false);
    		}
    	else
    	{
    		MainFrame.sif.setTextAbled(false);
    		setStudentInfoFrameContent(MainFrame.sif);
    		MainFrame.sif.setVisible(true);
            MainFrame.sif.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    		MainFrame.sif.setButton(true, true, true, false, false);
    	}
    }
    
}

⌨️ 快捷键说明

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