📄 addbranchdialog.java
字号:
package com.tarena.abs.server;
import javax.swing.*;
import com.tarena.abs.dao.*;
import com.tarena.abs.model.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
/**
* 添加代理商对话框。
* @author tangliang
*
*/
public class AddBranchDialog extends JDialog implements ActionListener{
JLabel label0,label1,label2,label3,label4;
JButton ok,cancel;
JTextField name,city,passwd,address;
public AddBranchDialog(JFrame frame){
super(frame,"添加网点");
label0=new JLabel("请输入网点信息:");
label1=new JLabel(" 网点名:");
label2=new JLabel(" 密码:");
label3=new JLabel(" 城市:");
label4=new JLabel(" 地址:");
ok=new JButton("添加");
cancel=new JButton("取消");
name=new JTextField(15);
passwd=new JTextField(15);
city=new JTextField(15);
address=new JTextField(15);
init();
eventHandle();
}
private void init(){
JPanel p1=new JPanel();
p1.add(label0);
this.add(p1,BorderLayout.NORTH);
JPanel p2=new JPanel();
p2.setLayout(new GridLayout(4,2,10,20));
p2.add(label1);
p2.add(name);
p2.add(label2);
p2.add(passwd);
p2.add(label3);
p2.add(city);
p2.add(label4);
p2.add(address);
this.add(p2,BorderLayout.CENTER);
JPanel p3=new JPanel();
p3.add(ok);
p3.add(cancel);
this.add(p3,BorderLayout.SOUTH);
}
private void eventHandle(){
ok.addActionListener(this);
cancel.addActionListener(this);
}
public void showMe(){
this.setSize(500,250);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String comm=e.getActionCommand();
if(comm.equals("添加")){
if(name.getText().equals("")||passwd.getText().equals("")||city.getText().equals("")||address.getText().equals("")){
JOptionPane.showMessageDialog(this,"请填写所有信息!");
return;
}
BranchDAO dao=ServerMainClass.agentDao;
boolean success=dao.addBranch(new Branch(name.getText(),passwd.getText(),city.getText(),address.getText()));
if(success){
JOptionPane.showMessageDialog(this,"祝贺,网点添加成功!");
this.dispose();
}else{
JOptionPane.showMessageDialog(this,"网点添加不成功,可能已存在同名的网点!");
name.setText("");
passwd.setText("");
city.setText("");
address.setText("");
}
}else if(comm.equals("取消")){
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -