📄 updateprojectinfo.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 UpdateProjectInfo 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 JTextField t4 = null;
private JLabel jLabel5 = null;
private JTextField t5 = null;
private JLabel jLabel6 = null;
private JTextField t6 = null;
private JButton ok = null;
private JButton cancel = null;
private JComboBox jComboBox1 = null;
/**
* This method initializes
*
*/
public UpdateProjectInfo() {
super();
initialize();
}
public UpdateProjectInfo(MainFrame m) {
super(m);
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(20, 237, 46, 27));
jLabel6.setText("举办日");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(21, 197, 45, 26));
jLabel5.setText("举办地");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(22, 160, 43, 26));
jLabel4.setText("电 话");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(23, 121, 41, 26));
jLabel3.setText("负责人");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(24, 84, 42, 25));
jLabel2.setText("项目名");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(24, 43, 43, 25));
jLabel1.setText("代 号");
this.setSize(new Dimension(260, 309));
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(getT4(), null);
this.add(jLabel5, null);
this.add(getT5(), null);
this.add(jLabel6, null);
this.add(getT6(), null);
this.add(getOk(), null);
this.add(getCancel(), 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(102, 83, 123, 26));
}
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(101, 122, 123, 27));
}
return t3;
}
/**
* This method initializes t4
* @return javax.swing.JTextField
* @uml.property name="t4"
*/
private JTextField getT4() {
if (t4 == null) {
t4 = new JTextField();
t4.setBounds(new Rectangle(100, 161, 122, 26));
}
return t4;
}
/**
* This method initializes t5
* @return javax.swing.JTextField
* @uml.property name="t5"
*/
private JTextField getT5() {
if (t5 == null) {
t5 = new JTextField();
t5.setBounds(new Rectangle(99, 198, 123, 27));
}
return t5;
}
/**
* This method initializes t6
* @return javax.swing.JTextField
* @uml.property name="t6"
*/
private JTextField getT6() {
if (t6 == null) {
t6 = new JTextField();
t6.setBounds(new Rectangle(99, 238, 122, 26));
}
return t6;
}
/**
* 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, 276, 74, 26));
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(159, 276, 82, 27));
cancel.setText("取消");
cancel.addActionListener(this);
}
return cancel;
}
@Override
public void actionPerformed(ActionEvent e) {
String s1="",s2="";
if(e.getSource()==ok){
s1=jComboBox1.getSelectedItem().toString().trim();
s2=t2.getText().toString().trim();
String s3=t3.getText().toString().trim();
String s4=t4.getText().toString().trim();
String s5=t5.getText().toString().trim();
String s6=t6.getText().toString().trim();
if(s1.equals("")||s2.equals("")||s3.equals("")||s4.equals("")||s5.equals("")||s6.equals(""))
{
JOptionPane.showMessageDialog(this,"有些信息为空,请检查。");
return;
}
String sql="select * from project where id='"+s1+"'";
ResultSet rs=db.executeQuery(sql);
try {
if(!rs.next()){
JOptionPane.showMessageDialog(this,"该项目不存在。");
return;
}
else{
sql="update project set name='"+s2+"',principal='"+s3+"',phone='"+s4+"',address='"+s5+"',date='"+s6+"' where id='"+s1+"'";
System.out.println(sql);
if(db.executeUpdate(sql)){
JOptionPane.showMessageDialog(this,"项目修改成功。");
}
else{
JOptionPane.showMessageDialog(this,"操作失败,可能是日期有错误。");
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==cancel){
this.dispose();
if(m!=null)
m.setVisible(true);
db.close();
}
else{
s1=jComboBox1.getSelectedItem().toString().trim();
String sql="select * from project where id='"+s1+"'";
System.out.println(sql);
ResultSet rs=db.executeQuery(sql);
try {
if(!rs.next()){
JOptionPane.showMessageDialog(this,"该项目不存在。");
return;
}
else{
t2.setText(rs.getString("name"));
t3.setText(rs.getString("principal"));
t4.setText(rs.getString("phone"));
t5.setText(rs.getString("address"));
t6.setText(rs.getString("date"));
}
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
/**
* 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(102, 39, 123, 31));
ResultSet rs=db.executeQuery("select * from project");
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="336,-3"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -