📄 pmainmenu.java~127~
字号:
JMenuItem jMenuItem22 = new JMenuItem();
JScrollPane jScrollPane3 = new JScrollPane();
JTree jTree2 = new JTree();
JTextField jTextField4 = new JTextField();
Border border1 = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.yellow);
public void jPanel3_mouseClicked(MouseEvent e) {
int num = (int)Math.round(Math.random()*9);
ImageIcon image=new ImageIcon("/Jewelry/desktop/20050118xy001_("+num+").jpg");
}
public void jButton4_mouseClicked(MouseEvent e) {
}
public void jButton6_actionPerformed(ActionEvent e) {
SMainMenu sm = new SMainMenu();
Thread thr = new Thread(sm);
thr.start();
this.dispose();
}
public void jButton5_actionPerformed(ActionEvent e) {
SMainMenu sm = new SMainMenu(); //
sm.baseButton(e); //
Thread thr = new Thread(sm);
thr.start();
this.dispose();
}
public void jButton4_actionPerformed(ActionEvent e) {
CSMainMenu cs = new CSMainMenu();
Thread thr = new Thread(cs);
thr.start();
this.dispose();
}
public void getTime(){
Date date = new Date();
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
txtDate.setText(fmt.format(date));
}
public void jButton8_actionPerformed(ActionEvent e) throws SQLException {
SPerControl sp = new SPerControl();
if(this.jComboBox2.getSelectedItem().equals("--请选择--")){
txtAdd.setText("");
txtAge.setText("");
txtId.setText("");
txtName.setText("");
txtPhone.setText("");
txtSex.setText("");
JOptionPane.showMessageDialog(this, "请选择填写的方式");
return;
}
if(this.jComboBox2.getSelectedItem().equals("增加")){
String id = txtId.getText(); //编号 //
String name = txtName.getText(); //姓名 //
String sex = txtSex.getText(); //性别 //
String age = txtAge.getText(); //年龄 //
String duty= jComboBox3.getSelectedItem().toString(); //状态
String phone = txtPhone.getText(); //电话 //
String add = txtAdd.getText(); //地址
String stat = this.jComboBox4.getSelectedItem().toString(); // 职务
String time = this.txtDate.getText(); //时间
//判断编号是否为空
if(id.equals("")){
JOptionPane.showMessageDialog(this, "编号不能为空");
return;
}
//判断输入的编号是否以存在
Vector ve = sp.query1(id);
if (ve.size() != 0) {
JOptionPane.showMessageDialog(this, "此编号已存在");
return;
}
//判断姓名是否为空
if(name.equals("")){
JOptionPane.showMessageDialog(this, "姓名不能为空");
return;
}
if(name.length() < 2 | name.length() > 4){
JOptionPane.showMessageDialog(this, "姓名字符输入有误");
return;
}
//判断性别是否为空
if(!(sex.equals("男"))&& !(sex.equals("女"))){
JOptionPane.showMessageDialog(this, "性别不能为空");
return;
}
//判断输入的年龄是否为空
if(age.equals("")){
JOptionPane.showMessageDialog(this, "年龄不能为空");
return;
}
//判断输入的年龄是否为整数字
try {
Integer.parseInt(txtAge.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年龄必须为整数");
return;
}
//判断输入的年龄是否小于 18 岁
if(Integer.parseInt(age) < 18 || Integer.parseInt(age) > 60){
JOptionPane.showMessageDialog(this,""+ age +" 年龄输入不对");
return;
}
//判断输入的电话是否为空
if(phone.equals("")){
JOptionPane.showMessageDialog(this, "电话号码不能为空");
return;
}
//判断输入的电话号码是否为数字
try {
Float.parseFloat(this.txtPhone.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "电话号码必须为数字");
return;
}
//判断输入的电话号码是否以 13 获 159 开头
float num1;
float num2;
num1 = Float.parseFloat(phone.substring(0,2));
num2 = Float.parseFloat(phone.substring(0,3));
if((num1 != 13) && (num2 != 159)){
JOptionPane.showMessageDialog(this, "电话号码输入有误");
return;
}
//判断输入的电话号码是否已存在
Vector vec = sp.query7(phone);
if(vec.size() != 0){
JOptionPane.showMessageDialog(this, "此电话号码已存在");
return;
}
ArrayList arraylist = sp.cont(id,name,sex,age,stat,phone,add,duty,time);
if(arraylist == null){
JOptionPane.showMessageDialog(this, "增加失败");
}else{
JOptionPane.showMessageDialog(this, "增加成功");
this.jbInit1();
}
}else{
String id = null; //编号
String name = null; //姓名
String sex = null; //性别
String age = null; //年龄
String time = null; //日期
String stat = null; //状态
String phone = null; //电话
String add = null; //地址
String duty = null; //职务
id = this.txtId.getText();
name = this.txtName.getText();
time = this.txtDate.getText();
sex = this.txtSex.getText();
age = this.txtAge.getText();
add = this.txtAdd.getText();
phone = this.txtPhone.getText();
stat = jComboBox3.getSelectedItem().toString(); //获得状态
duty = this.jComboBox4.getSelectedItem().toString(); //职务
///////////////////////////////////////////////////////////////
//判断编号是否为空
if(id.equals("")){
JOptionPane.showMessageDialog(this, "编号不能为空");
return;
}
//判断姓名是否为空
if(name.equals("")){
JOptionPane.showMessageDialog(this, "姓名不能为空");
return;
}
//判断性别是否为空
if(!(sex.equals("男"))&& !(sex.equals("女"))){
JOptionPane.showMessageDialog(this, "性别不能为空");
return;
}
//判断输入的年龄是否为空
if(age.equals("")){
JOptionPane.showMessageDialog(this, "年龄不能为空");
return;
}
//判断输入的年龄是否为整数字
try {
Integer.parseInt(txtAge.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年龄必须为整数");
return;
}
//判断输入的年龄是否小于 18 岁
if(Integer.parseInt(age) < 18 || Integer.parseInt(age) > 60){
JOptionPane.showMessageDialog(this,""+ age +" 年龄输入不对");
return;
}
//判断输入的电话是否为空
if(phone.equals("")){
JOptionPane.showMessageDialog(this, "电话号码不能为空");
return;
}
//判断输入的电话号码是否为数字
try {
Float.parseFloat(this.txtPhone.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "电话号码必须为数字");
return;
}
//判断输入的电话号码是否以 13 获 159 开头
float num1;
float num2;
num1 = Float.parseFloat(phone.substring(0,2));
num2 = Float.parseFloat(phone.substring(0,3));
if((num1 != 13) && (num2 != 159)){
JOptionPane.showMessageDialog(this, "电话号码输入有误");
return;
}
///////////////////////////////////////////////////////////////
ArrayList arraylist = sp.amend(id,name,time,sex,age,add,phone,stat,duty);
if(arraylist == null){
JOptionPane.showMessageDialog(this,"修改失败");
}else{
JOptionPane.showMessageDialog(this,"修改成功");
this.jbInit1();
}
}
}
public void jComboBox2_actionPerformed(ActionEvent e) {
this.getTime();
this.txtDate.setEditable(false);
if(this.jComboBox2.getSelectedItem().equals("修改")){
txtName.setEnabled(false);
this.txtSex.setEnabled(false);
this.txtAge.setEnabled(false);
}
if(this.jComboBox2.getSelectedItem().equals("增加")){
this.txtAge.setEnabled(true);
this.txtDate.setEnabled(false);
this.txtId.setEnabled(false);
this.txtName.setEnabled(true);
this.txtAdd.setEnabled(true);
this.txtPhone.setEnabled(true);
this.txtSex.setEnabled(true);
}
}
public void jComboBox2_mouseClicked(MouseEvent e) {
}
//jTable2单击事件
public void jTable2_mouseClicked(MouseEvent e) {
jTable2.setSelectionBackground(Color.green );
String id = null; // 编号
String name = null; //姓名
String sex = null; //性别
String age = null; //年龄
String duty = null; //职务
String phone = null; //电话
String add = null; //地址
String stat = null; //状态
String time = null; //时间
id = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 0).toString();
name = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 1).toString();
sex = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 2).toString();
age = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 3).toString();
duty = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 4).toString();
phone = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 5).toString();
add = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 6).toString();
stat = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 7).toString();
time = this.jTable2.getValueAt(this.jTable2.getSelectedRow(), 8).toString();
this.txtId.setText(id);
this.txtName.setText(name);
this.txtDate.setText(time);
this.txtSex.setText(sex);
this.txtAge.setText(age);
this.txtPhone.setText(phone);
this.txtAdd.setText(add);
}
/**
* 删除按钮点击事件
* @param e ActionEvent
* @throws SQLException
*/
public void jButton11_actionPerformed(ActionEvent e) throws SQLException {
SPerControl sp = new SPerControl();
if(this.jComboBox1.getSelectedItem().equals("编号")){
String id = txtTiao.getText(); //获得选择的编号
if (id.equals("")) {
JOptionPane.showMessageDialog(this, "请输入该条件的文本值");
return;
}
int arraylist = sp.amend1(id);
if (arraylist == 0) {
JOptionPane.showMessageDialog(this, "没有此编号");
} else {
JOptionPane.showMessageDialog(this, "删除成功");
this.jbInit1();
}
}
if(this.jComboBox1.getSelectedItem().equals("姓名")){
String name = txtTiao.getText(); //获得姓名
if (name.equals("")) {
JOptionPane.showMessageDialog(this, "请输入该条件的文本值");
return;
}
int arraylist = sp.amend2(name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -