📄 updateathleteinfo.java
字号:
package com.Update;
import com.MainFrame;
import com.component.MyFrame;
import java.awt.Dimension;
import java.awt.HeadlessException;
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 UpdateAthleteInfo extends MyFrame implements ActionListener {
private JLabel jLabel1 = 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;
private JComboBox jComboBox1 = null;
/**
* This method initializes
*
*/
public UpdateAthleteInfo(MainFrame m) {
super(m);
initialize();
}
public UpdateAthleteInfo() {
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(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.add(getJComboBox1(), null);
}
/**
* 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=jComboBox1.getSelectedItem().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,"该帐号不存在");
return;
}
else{
String sql="update athlete set name='"+name+"',academe='"+academe+"',sex='"+sex+"' where id="+id+"";
if(db.executeUpdate(sql)){
JOptionPane.showMessageDialog(this,"修改成功");
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==cancel){
dispose();
if(m!=null)
m.setVisible(true);
db.close();
}
else{
ResultSet rs=db.executeQuery("select * from athlete where id="+jComboBox1.getSelectedItem().toString().trim()+"");
try {
if(!rs.next())
JOptionPane.showMessageDialog(this,"该帐号不存在");
else
{
t2.setText(rs.getString("name"));
t3.setText(rs.getString("academe"));
}
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
/**
* 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;
}
/**
* 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(95, 55, 132, 33));
ResultSet rs=db.executeQuery("select * from Athlete");
try {
while(rs.next()){
jComboBox1.addItem(rs.getString("id").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
jComboBox1.setSelectedIndex(-1);
jComboBox1.addActionListener(this);
return jComboBox1;
}
} // @jve:decl-index=0:visual-constraint="329,35"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -