You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.3 KiB
118 lines
3.3 KiB
package view;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Font;
|
|
import java.awt.GridLayout;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import javax.swing.DefaultComboBoxModel;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JRadioButton;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import dao.GuanliyuanDao;
|
|
import dao.impl.GuanliyuanImpl;
|
|
import entity.Guanliyuan;
|
|
|
|
|
|
public class GuanliyuanAddUI extends JFrame {
|
|
|
|
private JPanel contentPane;
|
|
GuanliyuanDao dao = new GuanliyuanImpl();
|
|
public GuanliyuanAddUI() {
|
|
init(null);
|
|
}
|
|
public GuanliyuanAddUI(Tableinter mui) {
|
|
init(mui);
|
|
}
|
|
public void init(Tableinter mui) {
|
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
setBounds(100, 100, 643, 646);
|
|
contentPane = new JPanel();
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
setContentPane(contentPane);
|
|
contentPane.setLayout(null);
|
|
JPanel panel = new JPanel();
|
|
contentPane.add(panel);
|
|
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
|
JLabel yonghumingyclabel = new JLabel("用户名");
|
|
yonghumingyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
panel.add(yonghumingyclabel);
|
|
JTextField yonghumingyctextField = new JTextField();
|
|
panel.add(yonghumingyctextField);
|
|
|
|
JLabel mimayclabel = new JLabel("密码");
|
|
mimayclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
panel.add(mimayclabel);
|
|
JTextField mimayctextField = new JTextField();
|
|
panel.add(mimayctextField);
|
|
|
|
JLabel jiaoseyclabel = new JLabel("角色");
|
|
jiaoseyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
panel.add(jiaoseyclabel);
|
|
JComboBox jiaoseyccomboBox = new JComboBox();
|
|
jiaoseyccomboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
|
panel.add(jiaoseyccomboBox);
|
|
|
|
|
|
|
|
|
|
|
|
panel.setBounds(10, 10, 607, 90);
|
|
JButton button = new JButton("添加");
|
|
/**
|
|
新增按钮触发事件
|
|
*/
|
|
button.addMouseListener(new MouseAdapter() {
|
|
public void mouseClicked(MouseEvent e) {
|
|
Guanliyuan bean=new Guanliyuan();
|
|
bean.setYonghumingyc(yonghumingyctextField.getText());
|
|
|
|
bean.setMimayc(mimayctextField.getText());
|
|
|
|
bean.setJiaoseyc(jiaoseyccomboBox.getSelectedItem().toString());
|
|
|
|
|
|
dao.create(bean);
|
|
JOptionPane.showMessageDialog(null, "添加成功");
|
|
if(mui!=null)
|
|
mui.refresh(dao.findAll());
|
|
dispose();
|
|
}
|
|
});
|
|
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
|
button.setBounds(173, 550, 93, 47);
|
|
contentPane.add(button);
|
|
|
|
JButton button_1 = new JButton("取消");
|
|
button_1.addMouseListener(new MouseAdapter() {
|
|
public void mouseClicked(MouseEvent e) {
|
|
dispose();
|
|
}
|
|
});
|
|
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
|
button_1.setBounds(334, 550, 93, 47);
|
|
contentPane.add(button_1);
|
|
|
|
this.setLocationRelativeTo(null);
|
|
}
|
|
public String getRadioValue(JPanel panel){
|
|
for(Component c:panel.getComponents()){
|
|
if(c instanceof JRadioButton){
|
|
if(((JRadioButton) c).isSelected()){
|
|
return ((JRadioButton)c).getText();
|
|
}
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
}
|