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

📄 stinf.java

📁 一个简单的学生信息管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	subpanelperfect3.add(labelspecialtyperfect);
	textfieldspecialtyperfect=new JTextField(8);
	subpanelperfect3.add(textfieldspecialtyperfect);
	labelgradeperfect=new JLabel("班级:");
	subpanelperfect3.add(labelgradeperfect);
	textfieldgradeperfect=new JTextField(8);
	subpanelperfect3.add(textfieldgradeperfect);
	labelbirthdayperfect=new JLabel("出生:");
	subpanelperfect3.add(labelbirthdayperfect);
	textfieldbirthdayperfect=new JTextField(8);
	subpanelperfect3.add(textfieldbirthdayperfect);
	textfieldnameperfect.setEditable(false);
	textfieldspecialtyperfect.setEditable(false);
	textfieldgradeperfect.setEditable(false);
	textfieldbirthdayperfect.setEditable(false);
//设置subpanelperfect3布局
	GridBagLayout gblObjpanelperfect=new GridBagLayout();
	GridBagConstraints gbcObjpanelperfect=new GridBagConstraints();
	subpanelperfect3.setLayout(gblObjpanelperfect);
	gbcObjpanelperfect.weightx=1.0;
	gbcObjpanelperfect.weighty=1.0;
	gbcObjpanelperfect.anchor=GridBagConstraints.EAST;
	gbcObjpanelperfect.gridx=0;
	gbcObjpanelperfect.gridy=0;
	gblObjpanelperfect.setConstraints(labelNOperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=1;
	gblObjpanelperfect.setConstraints(labelnameperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=2;
	gblObjpanelperfect.setConstraints(labelsexperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=3;
	gblObjpanelperfect.setConstraints(labelspecialtyperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=4;
	gblObjpanelperfect.setConstraints(labelgradeperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=5;
	gblObjpanelperfect.setConstraints(labelbirthdayperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.anchor=GridBagConstraints.CENTER;
	gbcObjpanelperfect.gridx=1;
	gbcObjpanelperfect.gridy=0;
	gblObjpanelperfect.setConstraints(textfieldNOperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=1;
	gblObjpanelperfect.setConstraints(textfieldnameperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=2;
	gblObjpanelperfect.setConstraints(subpanelperfect5,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=3;
	gblObjpanelperfect.setConstraints(textfieldspecialtyperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=4;
	gblObjpanelperfect.setConstraints(textfieldgradeperfect,gbcObjpanelperfect);
	gbcObjpanelperfect.gridy=5;
	gblObjpanelperfect.setConstraints(textfieldbirthdayperfect,gbcObjpanelperfect);
//添加subpanelperfect4组键并设置布局
	subpanelperfect4=new JPanel();
	subpanelperfect4.setBackground(Color.green);
	labelinformationperfect=new JLabel("相关信息:");
	BorderLayout blObj1panelnew=new BorderLayout();
	subpanelperfect4.setLayout(blObj1panelnew);
	subpanelperfect4.add("North",labelinformationperfect);
	textareainformationperfect=new JTextArea(5,11);
	textareainformationperfect.setLineWrap(true);
	textareainformationperfect.setFont(new Font("18号字体",Font.TRUETYPE_FONT,18));
	textareainformationperfect.setEditable(false);
	subpanelperfect4.add("West",textareainformationperfect);
//添加subpanelperfect1组键并设置布局
	subpanelperfect1=new JPanel();
	subpanelperfect1.setBackground(Color.green);
	subpanelperfect1.add(subpanelperfect3);
	subpanelperfect1.add(subpanelperfect4);
	GridLayout glObjpanelperfect=new GridLayout(1,2);
	subpanelperfect1.setLayout(glObjpanelperfect);
//添加subpanelperfect2组键并设置布局
	subpanelperfect2=new JPanel();
	subpanelperfect2.setBackground(Color.green);
	buttonperfect=new JButton("修改");
	buttonresetperfect=new JButton("重置");
	subpanelperfect2.add(buttonperfect);
	subpanelperfect2.add(buttonresetperfect);
	FlowLayout flObjpanelperfect=new FlowLayout(FlowLayout.LEFT,20,10);
	subpanelperfect2.setLayout(flObjpanelperfect);
//添加panelnew组键并设置布局
	BorderLayout blObj2panelperfect=new BorderLayout();
	panelperfect.setLayout(blObj2panelperfect);
	panelperfect.add("Center",subpanelperfect1);
	panelperfect.add("South",subpanelperfect2);
 }
}

//为 查询 组键面板添加组键  400,270
class PanelCheck extends PanelPerfect
{
 JPanel subpanelcheck1,subpanelcheck2,subpanelcheck3,subpanelcheck4;
 JLabel labelcheckmeans,labelcheckdata;
 JComboBox comboboxcheckmeans;
 String checkstr[]={" 学号"," 姓名"," 班级"," 专业"," 出生"};
 JTextField textfieldcheckdata;
 JRadioButton rbutton3,rbutton4;
 JButton buttoncheck;
 JTable tablecheck;
 String[][] d={{"","","","","",""},{"","","","","",""},{"","","","","",""},{"","","","","",""},{"","","","","",""},{"","","","","",""},{"","","","","",""}};
 String[] n={"姓名","学号","性别","专业","班级","出生"};
 public PanelCheck()
 {
//添加subpanelcheck1组键并设置布局
	subpanelcheck1=new JPanel();
	subpanelcheck1.setBackground(Color.green);
	labelcheckmeans=new JLabel("查询方法:  ");
	labelcheckdata=new JLabel("匹配信息:  ");
	comboboxcheckmeans=new JComboBox(checkstr);
	textfieldcheckdata=new JTextField(8);
	rbutton3=new JRadioButton("完全匹配",true);
	rbutton3.setBackground(Color.green);
	rbutton4=new JRadioButton("使用通配符");
	rbutton4.setBackground(Color.green);
	ButtonGroup group3=new ButtonGroup();
	group3.add(rbutton3);
	group3.add(rbutton4);
	subpanelcheck3=new JPanel();
	subpanelcheck3.setBackground(Color.green);
	subpanelcheck1.add(labelcheckmeans);
	subpanelcheck1.add(subpanelcheck3);
	subpanelcheck1.add(labelcheckdata);
	subpanelcheck1.add(comboboxcheckmeans);
	subpanelcheck1.add(textfieldcheckdata);
	subpanelcheck1.add(rbutton3);
	subpanelcheck1.add(rbutton4);
	GridBagLayout gblObjcheck=new GridBagLayout();
	GridBagConstraints gbcObjcheck=new GridBagConstraints();
	subpanelcheck1.setLayout(gblObjcheck);
	gbcObjcheck.weightx=1.0;
	gbcObjcheck.weighty=1.0;
	gbcObjcheck.gridx=0;
	gbcObjcheck.gridy=0;
	gblObjcheck.setConstraints(labelcheckmeans,gbcObjcheck);
	gbcObjcheck.gridy=1;
	gblObjcheck.setConstraints(subpanelcheck3,gbcObjcheck);
	gbcObjcheck.gridy=2;
	gblObjcheck.setConstraints(labelcheckdata,gbcObjcheck);
	gbcObjcheck.anchor=GridBagConstraints.WEST;
	gbcObjcheck.gridx=1;
	gbcObjcheck.gridy=0;
	gblObjcheck.setConstraints(comboboxcheckmeans,gbcObjcheck);
	gbcObjcheck.gridy=2;
	gblObjcheck.setConstraints(textfieldcheckdata,gbcObjcheck);
	gbcObjcheck.gridx=2;
	gbcObjcheck.gridy=0;
	gblObjcheck.setConstraints(rbutton3,gbcObjcheck);
	gbcObjcheck.gridy=2;
	gblObjcheck.setConstraints(rbutton4,gbcObjcheck);
//添加subpanelcheck2组键并设置布局
	subpanelcheck2=new JPanel();
	subpanelcheck2.setBackground(Color.green);
	buttoncheck=new JButton("查找");
	subpanelcheck2.add(subpanelcheck1);
	subpanelcheck2.add(buttoncheck);
//添加subpanelcheck4组键并设置布局
	subpanelcheck4=new JPanel();
	subpanelcheck4.setBackground(Color.green);
	tablecheck=new JTable(d,n);
	Dimension dim=new Dimension(350,90);
	tablecheck.setPreferredScrollableViewportSize(dim);
	subpanelcheck4.add(new JScrollPane(tablecheck));
	BorderLayout blObjcheck=new BorderLayout();
	panelcheck.setLayout(blObjcheck);
	panelcheck.add("North",subpanelcheck2);
	panelcheck.add("Center",subpanelcheck4);
	

	mainframe.setVisible(true);
 }
}


//创建事件管理器
class EventTest extends PanelCheck
{
 Statement statement;
 ButtonEvent beObj;
 MenuEvent meObj;
 TextchangedEvent teObj;
 public EventTest(){}
 public EventTest(Statement statement)
 {
	this.statement=statement;
	beObj=new ButtonEvent();
	buttonnew.addActionListener(beObj);
	buttonreset.addActionListener(beObj);
	buttondelete.addActionListener(beObj);
	buttonperfect.addActionListener(beObj);
	buttonresetperfect.addActionListener(beObj);
	buttoncheck.addActionListener(beObj);
	meObj=new MenuEvent();
	menuitemnew.addActionListener(meObj);
	menuitemcheck.addActionListener(meObj);
	menuitemperfect.addActionListener(meObj);
	menuitemdelete.addActionListener(meObj);
	menuitemexit.addActionListener(meObj);
	menuitemhelp.addActionListener(meObj);
	teObj=new TextchangedEvent();
	textfieldNOperfect.addKeyListener(teObj);
 }

//内部类--button事件 
 class ButtonEvent implements ActionListener
 {
	public void actionPerformed(ActionEvent e)
       {
	Object obj=e.getSource();
	if(obj==buttonnew)
	{
	 try
	 {
		String sex;
		if(rbuttonboy.isSelected())sex="男";
			else sex="女";
		String sql="insert into liu (name,numb,sex,specialty,grade,birthday) values('"+textfieldname.getText()+"','"+textfieldNO.getText()+"','"+sex+"','"+textfieldspecialty.getText()+"','"+textfieldgrade.getText()+"','"+textfieldbirthday.getText()+"')";
		int rs = statement.executeUpdate(sql);
		JOptionPane.showMessageDialog(null,"命令成功执行,影响行数为:"+rs+"行");
		textareainformation.setText("姓名:"+textfieldname.getText()+"\n学号:"+textfieldNO.getText()+"\n性别:"+sex+"\n专业:"+textfieldspecialty.getText()+"\n班级:"+textfieldgrade.getText()+"\n出生:"+textfieldbirthday.getText());
	 }
	 catch(SQLException s)
	 {
//		System.out.println("SQL异常");
//		s.printStackTrace();
		JOptionPane.showMessageDialog(null,s.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 catch(Exception a)
	 {
//		System.out.println("Exception异常");
		JOptionPane.showMessageDialog(null,a.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	}
	if(obj==buttonreset)
	{
	 textfieldname.setText("");
	 textfieldNO.setText("");
	 rbuttonboy.setSelected(true);
	 textfieldspecialty.setText("");
	 textfieldgrade.setText("");
	 textfieldbirthday.setText("");
	 textareainformation.setText("");
	}
	if(obj==buttondelete)
	{
	 try
	   {
		String means="";
		if(comboboxmeans.getSelectedItem()==" 学号")
			means="numb";
		if(comboboxmeans.getSelectedItem()==" 姓名")
			means="name";
		if(comboboxmeans.getSelectedItem()==" 专业")
			means="specialty";
		if(comboboxmeans.getSelectedItem()==" 班级")
			means="grade";
		if(comboboxmeans.getSelectedItem()==" 出生")
			means="birthday";
		String data="";
		if(rbutton1.isSelected())data=means+"=\'"+textfielddata.getText()+"\'";
		else data=means+" like \'%"+textfielddata.getText()+"%\'";
		String sql="delete from liu where "+data+"";
		int rs = statement.executeUpdate(sql);
		String message="";
		if(rs==0)message="命令失败,"+comboboxmeans.getSelectedItem()+textfielddata.getText()+"未找到!";
		 else message="命令成功执行,影响行数为:"+rs+"行";
		JOptionPane.showMessageDialog(null,message);
	   }
	 catch(SQLException s)
	 {
//		System.out.println("SQL异常");
//		s.printStackTrace();
		JOptionPane.showMessageDialog(null,s.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 catch(Exception a)
	 {
//		System.out.println("Exception异常");
		JOptionPane.showMessageDialog(null,a.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	}
	if(obj==buttonperfect)
	{
	 try
	 {
		String sex;
		if(rbuttonboyperfect.isSelected())sex="男";
			else sex="女";
		String sql="UPDATE liu SET name='"+textfieldnameperfect.getText()+"',sex='"+sex+"',specialty='"+textfieldspecialtyperfect.getText()+"',grade='"+textfieldgradeperfect.getText()+"',birthday='"+textfieldbirthdayperfect.getText()+"' WHERE numb='"+textfieldNOperfect.getText()+"'";
		int rs = statement.executeUpdate(sql);
		String message="";
		if(rs==0)message="命令失败,"+labelNOperfect.getText()+textfieldNOperfect.getText()+"未找到!";
		 else message="命令成功执行,影响行数为:"+rs+"行";
		JOptionPane.showMessageDialog(null,message);
		textareainformationperfect.setText("姓名:"+textfieldnameperfect.getText()+"\n学号:"+textfieldNOperfect.getText()+"\n性别:"+sex+"\n专业:"+textfieldspecialtyperfect.getText()+"\n班级:"+textfieldgradeperfect.getText()+"\n出生:"+textfieldbirthdayperfect.getText());
	 }
	 catch(SQLException s)
	 {
//		System.out.println("SQL异常");
//		s.printStackTrace();
		JOptionPane.showMessageDialog(null,s.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 catch(Exception a)
	 {
//		System.out.println("Exception异常");
		JOptionPane.showMessageDialog(null,a.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	}
	if(obj==buttonresetperfect)
	{
	 textfieldnameperfect.setText("");
	 textfieldNOperfect.setText("");
	 rbuttonboyperfect.setSelected(true);
	 textfieldspecialtyperfect.setText("");
	 textfieldgradeperfect.setText("");
	 textfieldbirthdayperfect.setText("");
	 textareainformationperfect.setText("");
	}
	if(obj==buttoncheck)
	{
	 for(int j=0;j<7;j++)
	  for(int i=0;i<6;i++)tablecheck.setValueAt("",j,i);
	 try
	   {
		String means1="";
		if(comboboxcheckmeans.getSelectedItem()==" 学号")
			means1="numb";
		if(comboboxcheckmeans.getSelectedItem()==" 姓名")
			means1="name";
		if(comboboxcheckmeans.getSelectedItem()==" 专业")
			means1="specialty";
		if(comboboxcheckmeans.getSelectedItem()==" 班级")
			means1="grade";
		if(comboboxcheckmeans.getSelectedItem()==" 出生")
			means1="birthday";
		String data1="";
		if(rbutton3.isSelected())data1=means1+"=\'"+textfieldcheckdata.getText()+"\'";
		else data1=means1+" like \'%"+textfieldcheckdata.getText()+"%\'";
		String query="select * from liu where "+data1+"";		
		ResultSet rs = statement.executeQuery( query );
		int j=0;
		while(rs.next())
		{
		 for(int i=0;i<6;i++)
		 tablecheck.setValueAt(rs.getObject(i+1),j,i);
		 j++;
		}
	    }
	 catch(SQLException s)
	 {
//		System.out.println("SQL异常");
//		s.printStackTrace();
		JOptionPane.showMessageDialog(null,s.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 catch(Exception a)
	 {
//		System.out.println("Exception异常");
		JOptionPane.showMessageDialog(null,a.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	}
	
       }
 }

//内部类--textfield事件
 class TextchangedEvent extends KeyAdapter
 {
	public void keyReleased(KeyEvent e)
       {
		System.out.println(textfieldNOperfect.getText());
	 if(!textfieldNOperfect.getText().equalsIgnoreCase(""))
	 {
		textfieldnameperfect.setEditable(true);
		textfieldspecialtyperfect.setEditable(true);
		textfieldgradeperfect.setEditable(true);
		textfieldbirthdayperfect.setEditable(true);
		textareainformationperfect.setEditable(true);
	 }
	  else
	 {
		textfieldnameperfect.setEditable(false);
		textfieldspecialtyperfect.setEditable(false);
		textfieldgradeperfect.setEditable(false);
		textfieldbirthdayperfect.setEditable(false);
		textareainformationperfect.setEditable(false);
	 }
       }
 }


//内部类--menubar事件 
 class MenuEvent implements ActionListener
 {
	public void actionPerformed(ActionEvent e)
       {
	Object obj=e.getSource();
	if(obj==menuitemnew)
	{mainframe.setSize(400,300);cardlayoutObj.show(mainpanel,"Card2");}
	if(obj==menuitemcheck)
	{mainframe.setSize(400,270);cardlayoutObj.show(mainpanel,"Card3");}
	if(obj==menuitemperfect)
	{mainframe.setSize(400,300);cardlayoutObj.show(mainpanel,"Card4");}
	if(obj==menuitemdelete)
	{mainframe.setSize(250,200);mainframe.setVisible(true);cardlayoutObj.show(mainpanel,"Card5");}
	if(obj==menuitemhelp)
	{mainframe.setSize(400,300);cardlayoutObj.show(mainpanel,"Card1");}
	if(obj==menuitemexit)
	{
	 try
	  {
		statement.close();
	  }
	 catch(SQLException s)
	 {
//		System.out.println("SQL异常");
//		s.printStackTrace();
		JOptionPane.showMessageDialog(null,s.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 catch(Exception a)
	 {
//		System.out.println("Exception异常");
		JOptionPane.showMessageDialog(null,a.toString(),"警告!",JOptionPane.WARNING_MESSAGE);
	 }
	 System.exit(0);
	}
       }
 } 
}

//mian类
public class stinf
{
 public static void main(String[] args)
 {
	new Load();
 }
}

⌨️ 快捷键说明

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