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

📄 updategroupinfo.java

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

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;

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

	private JLabel jLabel1 = null;
	private JComboBox jComboBox1 = null;
	private JLabel jLabel2 = null;
	private JComboBox jComboBox2 = null;
	private JButton add = null;
	private JButton cancel = null;

	/**
	 * This method initializes 
	 * 
	 */
	public UpdateGroupInfo(MainFrame m) {
		super(m);
		initialize();
	}
	public UpdateGroupInfo() {
		super();
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        jLabel2 = new JLabel();
        jLabel2.setBounds(new Rectangle(18, 83, 59, 34));
        jLabel2.setText("运动员号");
        jLabel1 = new JLabel();
        jLabel1.setBounds(new Rectangle(19, 35, 56, 31));
        jLabel1.setText("选择团队");
        this.setSize(new Dimension(295, 204));
        this.setTitle("删除团队成员");
        this.add(jLabel1, null);
        this.add(getJComboBox1(), null);
        this.add(jLabel2, null);
        this.add(getJComboBox2(), null);
        this.add(getAdd(), null);
        this.add(getCancel(), null);
			
	}

	/**
	 * This method initializes jComboBox1	
	 * @return  javax.swing.JComboBox
	 * @uml.property  name="jComboBox1"
	 */
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			jComboBox1.setBounds(new Rectangle(103, 34, 144, 34));
			
			ResultSet rs=db.executeQuery("select * from groupinfo");
			try {
				while(rs.next()){
					jComboBox1.addItem(rs.getString("name"));
				}
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
		}
		jComboBox1.setSelectedIndex(-1);
		return jComboBox1;
	}

	/**
	 * This method initializes jComboBox2	
	 * @return  javax.swing.JComboBox
	 * @uml.property  name="jComboBox2"
	 */
	private JComboBox getJComboBox2() {
		if (jComboBox2 == null) {
			jComboBox2 = new JComboBox();
			jComboBox2.setBounds(new Rectangle(102, 83, 145, 34));
			
			ResultSet rs=db.executeQuery("select * from Athlete");
			try {
				while(rs.next()){
					jComboBox2.addItem(rs.getString("id"));
				}
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
		
		}
		jComboBox2.setSelectedIndex(-1);
		return jComboBox2;
	}

	/**
	 * @return  the add
	 * @uml.property  name="add"
	 */
	private JButton getAdd() {
		if (add == null) {
			add = new JButton();
			add.setBounds(new Rectangle(29, 153, 77, 36));
			add.setText("确定");
			add.addActionListener(this);
		}
		return add;
	}

	/**
	 * 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(171, 151, 83, 38));
			cancel.setText("取消");
			cancel.addActionListener(this);
		}
		return cancel;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource()==cancel){
			db.close();
			if(m!=null)
			m.setVisible(true);
			dispose();
			return;
		}
		String groupID=db.getString("select * from groupInfo where name='"+jComboBox1.getSelectedItem().toString().trim()+"'", "groupid");
		String athlete=jComboBox2.getSelectedItem().toString().trim();
		if(e.getSource()==add)
		{
			ResultSet rs=db.executeQuery("select * from groupathlete where groupid="+groupID+" and athlete="+athlete+"");
		    try {
				if(!rs.next()){
					JOptionPane.showMessageDialog(this,"已经删除了");
				}
				else{
					
					if(db.executeUpdate("delete from groupathlete where groupid="+groupID+" and athlete="+athlete+""))
					{
						if(db.executeUpdate("update groupinfo set athleteamount=athleteamount-1 where groupId="+groupID+""))
						   JOptionPane.showMessageDialog(this,"删除成功");
						else{
							 db.executeQuery("delete from groupathlete where athlete="+athlete+" ");
							
						}
						  
						
					}
					
				}
			}  catch (SQLException e1) {
				
				e1.printStackTrace();
			}
		}
	
	}

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

⌨️ 快捷键说明

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