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

📄 j_studentinsert.java

📁 简单的学生管理系统系统
💻 JAVA
字号:
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class J_studentinsert extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel11 = null;
	private JLabel jLabel12 = null;
	private JLabel jLabel13 = null;
	private   JTextField jtfxingming = null;
	private JTextField jtfxuehao = null;
	private  JTextField jtfage = null;
	private  JTextField jtfaddress = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private   JFileChooser  jchose=null;
	public static   String m_stri=null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JTextField jtftelphone = null;
	private JLabel jLabel2 = null;
	private JRadioButton jrbman = null;
	private JRadioButton jrbgirl = null;
	
	private String m_sex=null;
	/**
	 * This is the default constructor
	 */
	public J_studentinsert() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel4 = new JLabel();
		jLabel4.setBounds(new Rectangle(27, 179, 63, 32));
		jLabel4.setText("性别:");
		jLabel3 = new JLabel();
		jLabel3.setBounds(new Rectangle(291, 77, 141, 128));
		jLabel3.setIcon(new ImageIcon("52065.gif"));
		jLabel3.setText("照片");
		jLabel13 = new JLabel();
		jLabel13.setBounds(new Rectangle(24, 273, 71, 28));
		jLabel13.setText("电话:");
		jLabel12 = new JLabel();
		jLabel12.setBounds(new Rectangle(25, 224, 65, 32));
		jLabel12.setText("家庭住址:");
		jLabel11 = new JLabel();
		jLabel11.setBounds(new Rectangle(27, 137, 66, 29));
		jLabel11.setText("年龄:");
		jLabel1 = new JLabel();
		jLabel1.setBounds(new Rectangle(26, 99, 66, 26));
		jLabel1.setText("学号:");
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(26, 61, 68, 28));
		jLabel.setText("姓名:");
		this.setSize(465, 367);
		this.setLayout(null);
		this.setBackground(SystemColor.activeCaption);
		this.add(jLabel, null);
		this.add(jLabel1, null);
		this.add(jLabel11, null);
		this.add(jLabel12, null);
		this.add(jLabel13, null);
		this.add(getJtfxingming(), null);
		this.add(getJtfxuehao(), null);
		this.add(getJtfage(), null);
		this.add(getJtfaddress(), null);
		this.add(getJButton(), null);
		this.add(getJButton1(), null);
		this.add(jLabel3, null);
		this.add(jLabel4, null);
		this.add(getJtftelphone(), null);
		this.add(getJLabel2(), null);
		this.add(getJrbman(), null);
		this.add(getJrbgirl(), null);
		ImageIcon ic=new ImageIcon("shui.jpg");
		JLabel jbl=new JLabel();
		jbl.setIcon(ic);
		jbl.setBounds(new Rectangle(0, 1, 466, 366));
		this.setOpaque(false);
		this.add(jbl, null);
	}

	/**
	 * This method initializes jtfxingming	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJtfxingming() {
		if (jtfxingming == null) {
			jtfxingming = new JTextField();
			jtfxingming.setBounds(new Rectangle(103, 57, 158, 31));
		}
		return jtfxingming;
	}

	/**
	 * This method initializes jtfxuehao	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJtfxuehao() {
		if (jtfxuehao == null) {
			jtfxuehao = new JTextField();
			jtfxuehao.setBounds(new Rectangle(104, 103, 157, 30));
		}
		return jtfxuehao;
	}

	/**
	 * This method initializes jtfage	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJtfage() {
		if (jtfage == null) {
			jtfage = new JTextField();
			jtfage.setBounds(new Rectangle(102, 137, 157, 30));
		}
		return jtfage;
	}

	/**
	 * This method initializes jtfaddress	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJtfaddress() {
		if (jtfaddress == null) {
			jtfaddress = new JTextField();
			jtfaddress.setBounds(new Rectangle(103, 222, 163, 31));
		}
		return jtfaddress;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() 
	{
		if (jButton == null) 
		{
			jButton = new JButton();
			jButton.setBounds(new Rectangle(354, 207, 77, 28));
			jButton.setText("浏览");
			jButton.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					try
					{
					  jchose=new JFileChooser();
					  int n=jchose.showOpenDialog(null);
					  m_stri=jchose.getSelectedFile().getName();
					  if(n==0)
				      {
					      jLabel3.setIcon(new ImageIcon(m_stri));
                          jLabel3.setVisible(true);
				      }
					}
					catch (Exception e1) 
					{}
					  
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() 
	{
		if (jButton1 == null) 
		{
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(328, 331, 106, 32));
			jButton1.setText("添加");
			jButton1.addActionListener(new java.awt.event.ActionListener()
			{
				public void actionPerformed(java.awt.event.ActionEvent e)
				{
					try
				    {   
						if(!jtfxingming.getText().isEmpty()&&!jtfxuehao.getText().isEmpty())
						{
							if(jrbman.isSelected()==true)
				            {
				        	m_sex="男";
				             }
				            else
				            {
				        	m_sex="女";
				             }
				        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				       	Connection c=DriverManager.getConnection("jdbc:odbc:studentSqlDatabase","sa","");
				    	Statement s=c.createStatement();
        		    	s.executeUpdate("insert into  "+J_Denglu.m_strbanji+"(姓名,学号,年龄,性别,家庭住址,电话,照片)  values('"+
				    			jtfxingming.getText() +"','"+jtfxuehao.getText() +"','"+
				  	        	jtfage.getText() +"','"+m_sex +"','"+jtfaddress.getText() +"','"+
				    			jtftelphone.getText() +"','"+m_stri+"')");
				    	s.close();
				    	c.close();
				    	System.out.println("添加成功!");
				    	JOptionPane.showMessageDialog(null,"添加成功!");
				    	}
						else 
							JOptionPane.showMessageDialog(null,"请输入姓名和学号!");
				    }
					
				        catch(Exception e1)
					    {
					    	System.err.println("异常"+e1.getMessage());
					    	JOptionPane.showMessageDialog(null,e1.getMessage());
					    }
				}
			});

		}
		return jButton1;
	}

	/**
	 * This method initializes jtftelphone	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJtftelphone() {
		if (jtftelphone == null) {
			jtftelphone = new JTextField();
			jtftelphone.setBounds(new Rectangle(105, 271, 167, 28));
		}
		return jtftelphone;
	}

	/**
	 * This method initializes jLabel2	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setText("请填写学生基本信息");
			jLabel2.setFont(new Font("Dialog", Font.BOLD, 18));
			jLabel2.setBounds(new Rectangle(151, 15, 182, 27));
		}
		return jLabel2;
	}

	/**
	 * This method initializes jrbman	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJrbman() {
		if (jrbman == null) {
			jrbman = new JRadioButton();
			jrbman.setBounds(new Rectangle(106, 178, 60, 32));
			jrbman.setText("男");
			jrbman.setSelected(true);
		}
		return jrbman;
	}

	/**
	 * This method initializes jrbgirl	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJrbgirl() {
		if (jrbgirl == null) {
			jrbgirl = new JRadioButton();
			jrbgirl.setBounds(new Rectangle(203, 179, 57, 30));
			jrbgirl.setText("女");
		    ButtonGroup btg=new ButtonGroup();
		    btg.add(jrbman);
		    btg.add(jrbgirl);
		}
		return jrbgirl;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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