import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 主菜单功能类
*/
public class Menu extends JFrame implements ActionListener {
private JButton jb1, jb2, jb3, jb4, jb5, jb6, jb7, jb8;
public String getTabName() {
return tabName;
}
public void setTabName(String tabName) {
this.tabName = tabName;
}
private String tabName = null;
Menu(String name) {
jb1 = new JButton("添加联系人");
jb2 = new JButton("删除联系人");
jb3 = new JButton("修改联系人");
jb4 = new JButton("查看联系人");
jb5 = new JButton("搜索联系人");
jb6 = new JButton("导入联系人");
jb7 = new JButton("导出联系人");
jb8 = new JButton("返回上一层");
setTabName(name);
}
public void launch() {
setLayout(null);
add(jb1);
jb1.setContentAreaFilled(false);
add(jb2);
jb1.setContentAreaFilled(false);
jb2.setContentAreaFilled(false);
jb3.setContentAreaFilled(false);
jb4.setContentAreaFilled(false);
jb5.setContentAreaFilled(false);
jb6.setContentAreaFilled(false);
jb7.setContentAreaFilled(false);
jb8.setContentAreaFilled(false);
add(jb3);
add(jb4);
add(jb5);
add(jb6);
add(jb7);
add(jb8);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
jb5.addActionListener(this);
jb6.addActionListener(this);
jb7.addActionListener(this);
jb8.addActionListener(this);
jb1.setBounds(20, 20, 150, 60);
jb2.setBounds(220, 20, 150, 60);
jb3.setBounds(20, 100, 150, 60);
jb4.setBounds(220, 100, 150, 60);
jb5.setBounds(20, 180, 150, 60);
jb6.setBounds(220, 180, 150, 60);
jb7.setBounds(20, 260, 150, 60);
jb8.setBounds(220, 260, 150, 60);
setTitle("通讯录管理程序");
setVisible(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int result = JOptionPane.showConfirmDialog(null, "确认退出?", "确认", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
System.exit(0);
}
}
});
setSize(400, 375);
setResizable(false);
setLocationRelativeTo(null);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("添加联系人")) {
dispose();
try {
new AddContact(getTabName()).launch();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} else if (e.getActionCommand().equals("删除联系人")) {
dispose();
new Delete(getTabName()).launch();
} else if (e.getActionCommand().equals("修改联系人")) {
dispose();
new Update(getTabName()).launch();
} else if (e.getActionCommand().equals("查看联系人")) {
dispose();
new ShowMessage(getTabName()).launch();
} else if (e.getActionCommand().equals("搜索联系人")) {
dispose();
new Find(getTabName()).launch();
} else if (e.getActionCommand().equals("导入联系人")) {
dispose();
new Input(getTabName()).launch();
} else if (e.getActionCommand().equals("导出联系人")) {
dispose();
new Export(getTabName()).launch();
} else if (e.getActionCommand().equals("返回上一层")) {
dispose();
new Login().launch();
}
}
}
/**
* 添加联系人
*/
class AddContact extends JFrame implements ActionListener {
private JPanel jp1, jp2, jp3, jp4, jp5, jp6, jp7, jp8;
private JLabel jl1, jl2, jl3, jl4, jl5, jl6;
private JTextField jtf1, jtf2, jtf3, jtf4, jtf5;
private JRadioButton jrb1, jrb2;
private JButton jb1, jb2;
private ButtonGroup buttonGroup;
private String table_name;
private JComboBox c1, c2, c3;
public String getTable_name() {
return table_name;
}
public void setTable_name(String table_name) {
this.table_name = table_name;
}
AddContact(String table_name) throws SQLException {
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp4 = new JPanel();
jp5 = new JPanel();
jp6 = new JPanel();
jp7 = new JPanel();
jp8 = new JPanel();
c1 = new JComboBox();
c2 = new JComboBox();
c3 = new JComboBox();
jl1 = new JLabel("姓名:");
jl2 = new JLabel("性别:");
jl3 = new JLabel("手机号:");
jl4 = new JLabel("邮箱:");
jl5 = new JLabel("详细地址:");
jl6 = new JLabel("QQ:");
jtf1 = new JTextField(15);
jtf2 = new JTextField(15);
jtf3 = new JTextField(15);
jtf4 = new JTextField(15);
jtf5 = new JTextField(15);
jrb1 = new JRadioButton("男", true);
jrb2 = new JRadioButton("女");
buttonGroup = new ButtonGroup();
jb1 = new JButton("添加");
jb1.addActionListener(this);
jb2 = new JButton("返回");
jb2.addActionListener(this);
setTable_name(table_name);
}
public static ArrayList<String> readCountry(String id) throws SQLException {
ArrayList<String> arrayList = new ArrayList<>();
MySql m = new MySql();
m.connect();
String sql = "select country from country where id = " + id;
Statement statement = m.getCon().createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
arrayList.add(resultSet.getString(1));
}
return arrayList;
}
public static ArrayList<String> readCounty(String id) throws SQLException {
ArrayList<String> arrayList = new ArrayList<>();
MySql m = new MySql();
m.connect();
String sql = "select county from county where id = " + id;
Statement statement = m.getCon().createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
arrayList.add(resultSet.getString(1));
}
return arrayList;
}
public static ArrayList<String> readProvince() throws SQLException {
ArrayList<String> arrayList = new ArrayList<>();
MySql m = new MySql();
m.connect();
String sql = "select province from province";
Statement statement = m.getCon().createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
arrayList.add(resultSet.getString(1));
}
return arrayList;
}
public void launch() throws SQLException {
c1.addItem("--请选择省--");
for (String a : readProvince()) {
c1.addItem(a);
}
c2.addItem("--请选择市--");
c3.addItem("--请选择区--");
c1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if
- 1
- 2
- 3
- 4
- 5
- 6
前往页