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

📄 insertathlete.java

📁 这是一个用java语言开发的运动员成绩统计系统
💻 JAVA
字号:
package com.insert;

import com.MainFrame;
import com.component.MyFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * @author  Laiger
 */
public class InsertAthlete extends MyFrame implements ActionListener {

	private JLabel jLabel1 = null;
	private JTextField t1 = null;
	private JLabel jLabel2 = null;
	private JTextField t2 = null;
	private JLabel jLabel3 = null;
	private JTextField t3 = null;
	private JLabel jLabel4 = null;
	private JButton ok = null;
	private JButton cancel = null;
	private JComboBox jComboBox = null;
	

	/**
	 * This method initializes 
	 * 
	 */
	public InsertAthlete(MainFrame m) {
		super(m);
		initialize();
	}
	public InsertAthlete() {
		super();
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        jLabel4 = new JLabel();
        jLabel4.setBounds(new Rectangle(14, 199, 51, 30));
        jLabel4.setText("性别");
        jLabel3 = new JLabel();
        jLabel3.setBounds(new Rectangle(14, 150, 51, 31));
        jLabel3.setText("学院");
        jLabel2 = new JLabel();
        jLabel2.setBounds(new Rectangle(13, 101, 51, 30));
        jLabel2.setText("姓名");
        jLabel1 = new JLabel();
        jLabel1.setBounds(new Rectangle(15, 55, 49, 30));
        jLabel1.setText("帐号");
        this.setSize(new Dimension(254, 315));
        this.setTitle("运动员信息录入");
        this.add(jLabel1, null);
        this.add(getT1(), null);
        this.add(jLabel2, null);
        this.add(getT2(), null);
        this.add(jLabel3, null);
        this.add(getT3(), null);
        this.add(jLabel4, null);
        this.add(getOk(), null);
        this.add(getCancel(), null);
        this.add(getJComboBox(), null);
			
	}

	/**
	 * This method initializes t1	
	 * @return  javax.swing.JTextField
	 * @uml.property  name="t1"
	 */
	private JTextField getT1() {
		if (t1 == null) {
			t1 = new JTextField();
			t1.setBounds(new Rectangle(96, 56, 139, 31));
		}
		return t1;
	}

	/**
	 * This method initializes t2	
	 * @return  javax.swing.JTextField
	 * @uml.property  name="t2"
	 */
	private JTextField getT2() {
		if (t2 == null) {
			t2 = new JTextField();
			t2.setBounds(new Rectangle(94, 103, 137, 31));
		}
		return t2;
	}

	/**
	 * This method initializes t3	
	 * @return  javax.swing.JTextField
	 * @uml.property  name="t3"
	 */
	private JTextField getT3() {
		if (t3 == null) {
			t3 = new JTextField();
			t3.setBounds(new Rectangle(92, 151, 136, 31));
		}
		return t3;
	}

	/**
	 * This method initializes ok	
	 * @return  javax.swing.JButton
	 * @uml.property  name="ok"
	 */
	private JButton getOk() {
		if (ok == null) {
			ok = new JButton();
			ok.setBounds(new Rectangle(24, 266, 65, 32));
			ok.setText("录入");
			ok.addActionListener(this);
		}
		return ok;
	}

	/**
	 * This method initializes cancel	
	 * @return  javax.swing.JButton
	 * @uml.property  name="cancel"
	 */
	private JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton();
			cancel.setBounds(new Rectangle(163, 264, 67, 32));
			cancel.setText("退出");
			cancel.addActionListener(this);
		}
		return cancel;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==ok){    
			String id=t1.getText().toString().trim();
			String name=t2.getText().toString().trim();
			String academe=t3.getText().toString().trim();
			String sex=jComboBox.getSelectedItem().toString().trim();
			if(id.equals("")){
				JOptionPane.showMessageDialog(this,"帐号不能为空");
				return;
			}
			if(name.equals("")){
				JOptionPane.showMessageDialog(this,"姓名为空");
				return;
			}
			if(academe.equals("")){
				JOptionPane.showMessageDialog(this,"学院名不能为空");
				return;
			}
			
			ResultSet rs=db.executeQuery("select * from athlete where id="+id+"");
			try {
				if(rs.next()){
					JOptionPane.showMessageDialog(this,"该帐号已经存在");
					t1.setText("");
					return;
				}
				else{
					String sql="insert into athlete values("+id+",'"+name+"','"+academe+"','"+sex+"')";
				
					if(db.executeUpdate(sql)){
					  JOptionPane.showMessageDialog(this,"添加成功");
					  t1.setText("");
					  t2.setText("");
					  t3.setText("");
					}
				}
			} catch (SQLException e1) {
				
				e1.printStackTrace();
			}
			
			
		}
		else { 
			dispose();
			if(m!=null)
			m.setVisible(true);
			db.close();
		}
		
	}

	/**
	 * This method initializes jComboBox	
	 * @return  javax.swing.JComboBox
	 * @uml.property  name="jComboBox"
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(92, 199, 135, 31));
			jComboBox.addItem("男");
			jComboBox.addItem("女");
		}
		return jComboBox;
	}

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

⌨️ 快捷键说明

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