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

📄 infoinsertjpanel.java

📁 学生信息管理系统 java + access
💻 JAVA
字号:
/**
 *文件;InfoInsertJPanel.java
 *说明:学生信息插入面版
 **/
 
 package com.javaseries.java.component;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.sql.*;

 
 public class InfoInsertJPanel extends JPanel
     implements ActionListener{
     	//声明标签
     	private JLabel JLsno=new JLabel("学    号:");
     	private JLabel JLname=new JLabel("姓    名:");
     	private JLabel JLsex=new JLabel("性    别:");
     	private JLabel JLbirthday=new JLabel("出生日期:");
     	private JLabel JLmophone=new JLabel("移动电话:");
     	private JLabel JLphone=new JLabel("固定电话:");
     	private JLabel JLdepartment=new JLabel("院系名称:");
     	private JLabel JLaddress=new JLabel("家庭住址:");
     	//声明文本输入框
     	private JTextField JTFsno = new JTextField(10);
     	private JTextField JTFsname = new JTextField(10);
     	private JTextField JTFsbirthday = new JTextField(10);
     	private JTextField JTFsmophone = new JTextField(10);
     	private JTextField JTFsphone = new JTextField(10);
     	private JTextField JTFsaddress = new JTextField(10);
     	//
     	private JRadioButton JRB1 = new JRadioButton("男",true);
     	private JRadioButton JRB2 = new JRadioButton("女");
     	//
     	private ButtonGroup BGsex = new ButtonGroup();
     	//
     	String depts[] = {"信息学院","经济学院","法学院","理学院","新闻学院","软件学院"};
     	//
     	private JComboBox JCBdepartment=new JComboBox(depts);
     	//
     	private JButton JBsubmit = new JButton("插入");
     	private JButton JBreset = new JButton("重置");
     	//
     	private JPanel JPLabels = new JPanel();
     	private JPanel JPsex = new JPanel();
     	private JPanel JPinputArea = new JPanel();
     	private JPanel JPechoArea = new JPanel();
     	private JPanel JPbuttons = new JPanel();
     	//
     	public InfoInsertJPanel(){
     		//
     		JPsex.setLayout(new GridLayout(1,2));
     		JPsex.add(JRB1);
     		JPsex.add(JRB2);
     		BGsex.add(JRB1);
     		BGsex.add(JRB2);
     		//
     		JPLabels.setLayout(new GridLayout(9,1,2,2));
     		JLsno.setHorizontalAlignment(SwingConstants.CENTER);
     		JLname.setHorizontalAlignment(SwingConstants.CENTER);
     		JLsex.setHorizontalAlignment(SwingConstants.CENTER);
     		JLbirthday.setHorizontalAlignment(SwingConstants.CENTER);
     		JLmophone.setHorizontalAlignment(SwingConstants.CENTER);
     		JLphone.setHorizontalAlignment(SwingConstants.CENTER);
     		JLdepartment.setHorizontalAlignment(SwingConstants.CENTER);
     		JLaddress.setHorizontalAlignment(SwingConstants.CENTER);
     		
     		JPLabels.add(JLsno);
     		JPLabels.add(JLname);
     		JPLabels.add(JLsex);
     		JPLabels.add(JLbirthday);
     		JPLabels.add(JLmophone);
     		JPLabels.add(JLphone);
     		JPLabels.add(JLdepartment);
     		JPLabels.add(JLaddress);
     		
     		//
     		JPinputArea.setLayout(new GridLayout(9,1,2,2));
     		JPinputArea.add(JTFsno);
     		JPinputArea.add(JTFsname);
     		JPinputArea.add(JPsex);
     		JPinputArea.add(JTFsbirthday);
     		JPinputArea.add(JTFsmophone);
     		JPinputArea.add(JTFsphone);
     		JPinputArea.add(JCBdepartment);
     		JPinputArea.add(JTFsaddress);
     		//
     		JPechoArea.setLayout(new GridLayout(1,2));
     		JPechoArea.add(JPLabels);
     		JPechoArea.add(JPinputArea);
     		//
     		JPbuttons.setLayout(new FlowLayout(FlowLayout.CENTER));
     		JPbuttons.add(JBsubmit);
     		JPbuttons.add(JBreset);
     		//
     		this.setLayout(new GridLayout(2,1));
     		this.add(JPechoArea);
     		this.add(JPbuttons);
     		//
     		JBsubmit.addActionListener(this);
     		JBreset.addActionListener(this);
         	}
     public void actionPerformed(ActionEvent e){
     	String Command=e.getActionCommand();
     	if(Command.equals("插入"))
     	{
     		insertDB();
     	}else if(Command.equals("重置")){
     		reset();
     	}
     }	
     	
     	//
     	private void insertDB(){
     		//
     		String sno = JTFsno.getText();
     		String name = JTFsname.getText();
     		String birthday = JTFsbirthday.getText();
     		String mophone = JTFsmophone.getText();
     		String phone = JTFsphone.getText();
     		String department = depts[JCBdepartment.getSelectedIndex()];
     		String address = JTFsaddress.getText();     		
                String sex=null;
     		if(JRB1.isSelected())
     		sex="男";
     		if(JRB2.isSelected())
     		sex="女";
     		System.out.println("--------组建输入数据如下--------");
     		System.out.println("学    号"+sno);
     		System.out.println("姓    名"+name);
     		System.out.println("性    别"+sex);
     		System.out.println("出生日期"+birthday);
     		System.out.println("移动电话"+mophone);
     		System.out.println("固定电话"+phone);
     		System.out.println("院系名称"+department);
     		System.out.println("家庭住址"+address);
     	
     		try{
     			InfoModelDB mydata=new InfoModelDB(sno,name,sex,birthday,mophone,phone,department,address);
     			mydata.Insert();
     				
     			}catch (SQLException e){
     				e.printStackTrace(); 
     				System.out.println("数据库操作出现问题!");
                 JOptionPane.showMessageDialog(null,"数据库操作出现问题!","警告",JOptionPane.INFORMATION_MESSAGE);

     			}catch (ClassNotFoundException e){
                 JOptionPane.showMessageDialog(null,"数据库操作出现问题!","警告",JOptionPane.INFORMATION_MESSAGE);
     				System.out.println("连接数据库操作的组建出现问题!");
     			}
     	
     		
     	}
     	
     	private void reset(){
     		JTFsno.setText("");
     		JTFsname.setText("");
     		JTFsbirthday.setText("");
     		
     		JRB1.setSelected(true);
     		JCBdepartment.setSelectedIndex(0);
     	}
     }

⌨️ 快捷键说明

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