package com.stu.pro;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
import java.util.*;
public class MyFrame extends JFrame implements ActionListener, MouseListener {
JList lt;
private JMenuBar mb;
private JMenu mu1, mu2, mu3, mu4;
private JMenuItem mi1, mi2, mi3, mi4, mi5, mi6, mi7;
DefaultListModel dm = new DefaultListModel();
JLabel lb = new JLabel("业精于勤荒于嬉,行成于思毁于随!");
public int j = 0;
public int m = 0;
public int t = 0;
public int d = 0, f = 0, h = 0, cag = 0, del = 0;
String str1[] = new String[20]; // 姓名
String str2[] = new String[20]; // 电话
String str3[] = new String[20]; // QQ
String str4[] = new String[20]; // 地址
String str5[] = new String[20]; // 邮编
// 中间面板
class mypan extends JPanel implements ActionListener {
JLabel Name, Tel, QQq, Address, youb, lb2, lb3, lb4, lb5, lb6;
JButton btn1, btn2, btn3;
mypan(int index) {
int x = index;
setLayout(null);
setBackground(Color.white);
Name = new JLabel(str1[x] + " 的联系方式");
Tel = new JLabel("电话:");
lb2 = new JLabel(str2[x]);
QQq = new JLabel("QQ:");
lb3 = new JLabel(str3[x]);
Address = new JLabel("地址:");
lb4 = new JLabel(str4[x]);
youb = new JLabel("邮编");
lb5 = new JLabel(str5[x]);
ImageIcon img6 = new ImageIcon("./res/image/2.jpg");
if (x == 1)
img6 = new ImageIcon("./res/image/3.jpg");
if (x == 2)
img6 = new ImageIcon("./res/image/4.jpg");
if (x == 3)
img6 = new ImageIcon("./res/image/5.jpg");
if (x == 4)
img6 = new ImageIcon("./res/image/6.jpg");
if (x == 5)
img6 = new ImageIcon("./res/image/7.jpg");
if (x == 6)
img6 = new ImageIcon("./res/image/8.jpg");
if (x == 7)
img6 = new ImageIcon("./res/image/8.jpg");
if (x == 8)
img6 = new ImageIcon("./res/image/9.jpg");
if (x == 9)
img6 = new ImageIcon("./res/image/10.jpg");
lb6 = new JLabel("", img6, SwingConstants.LEADING);
btn1 = new JButton("删除");
btn2 = new JButton("退出");
btn3 = new JButton("修改");
Name.setBounds(340, 30, 200, 30);
Name.setForeground(Color.blue);
Tel.setBounds(330, 80, 60, 30);
QQq.setBounds(330, 130, 60, 30);
Address.setBounds(330, 180, 60, 30);
youb.setBounds(330, 230, 60, 30);
lb2.setBounds(370, 80, 180, 30);
lb2.setForeground(Color.red);
lb3.setBounds(370, 130, 180, 30);
lb3.setForeground(Color.red);
lb4.setBounds(370, 180, 180, 30);
lb4.setForeground(Color.red);
lb5.setBounds(370, 230, 180, 30);
lb5.setForeground(Color.red);
lb6.setBounds(100, 50, 200, 200);
btn1.setBounds(250, 300, 60, 30);
btn2.setBounds(350, 300, 60, 30);
btn3.setBounds(150, 300, 60, 30);
this.add(btn1);
this.add(btn2);
this.add(btn3);
this.add(Name);
this.add(Tel);
this.add(QQq);
this.add(Address);
this.add(youb);
this.add(lb2);
this.add(lb3);
this.add(lb4);
this.add(lb5);
this.add(lb6);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
}
/*
* public void paint(Graphics g) {
*
*
* super.paint(g);
*
* ImageIcon img = newImageIcon("D:\\1.jpg");
*
* g.drawImage(img.getImage(), 200,100, 800, 300, this);
*
* }
*/
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
if (e.getSource() == btn1) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// 加载驱动程序
String url = "jdbc:odbc:chengwz";// URL指向要访问的数据库名test
String user = "";// MySQL配置时的用户名
String password = "";// MySQL配置时的密码
ResultSet rs = null;
Connection connection = DriverManager.getConnection(url, user, password);// 连续数据库
if (!connection.isClosed())
System.out.println("Succeededconnecting to the Database!");
Statement statement = connection.createStatement();// statement用来执行SQL语句
PreparedStatement pre = null;
String str2 = str1[f];
String sq2 = "delete * from cwz where name=?";
pre = connection.prepareStatement(sq2); // 要执行的SQL
pre.setString(1, str2);
pre.executeUpdate();
pre.close();
connection.close();
} catch (Exception ee) {
ee.printStackTrace();
System.out.println("============删除时:抛出异常===========");
}
dm.removeElementAt(f);
for (int d = f; d < j; d++) {
str1[d] = str1[d + 1];
str2[d] = str2[d + 1];
str3[d] = str3[d + 1];
str4[d] = str4[d + 1];
str5[d] = str5[d + 1];
}
j--;
f--;
JOptionPane.showMessageDialog(null, "数据删除成功!");
}
else if (e.getSource() == btn2) {
dispose();
System.exit(0);
}
else if (e.getSource() == btn3) {
new Revisefriend(f);
}
}
}
/*-----------------------------------------------------------------------------*/
mypan pn2 = new mypan(f);
mypan pnc = new mypan(f);
JLabel Name, Tel, QQq, Address, youb, lb2, lb3, lb4, lb5, lb6;
JButton btn1, btn2, btn3;
public MyFrame() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// 加载驱动程序
String url = "jdbc:odbc:chengwz";// URL指向要访问的数据库名test
String user = "";// MySQL配置时的用户名
String password = "";// MySQL配置时的密码
Connection connection = DriverManager.getConnection(url, user, password);// 连续数据库
if (!connection.isClosed())
System.out.println("Succeededconnecting to the Database!");
Statement statement = connection.createStatement();// statement用来执行SQL语句
String sql = "select * from cwz";// 要执行的SQL语句
ResultSet rs = statement.executeQuery(sql);// 执行SQL语句并返回结果集
String name = null;
String phone = null;
String QQ = null;
String youbian = null;
String address = null;
while (rs.next()) {
name = rs.getString("name");// 选择sname这列数据
phone = rs.getString("phone");
QQ = rs.getString("QQ");
address = rs.getString("address");
youbian = rs.getString("postcard");
str1[j] = name;
str2[j] = phone;
str3[j] = QQ;
str4[j] = address;
str5[j] = youbian;
j++;
dm.addElement(name + " " + phone + " " + address);
}
rs.close();// 关闭结果集
connection.close();// 关闭连接
} catch (ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
JPanel pn = new JPanel();
JPanel pn3 = new JPanel();
mypan pn2 = new mypan(f);
mb = new JMenuBar();
mu1 = new JMenu("好友操作");
mi1 = new JMenuItem("修改");
mi2 = new JMenuItem("删除");
mu2 = new JMenu("查询");
mi3 = new JMenuItem("按姓名");
mi4 = new JMenuItem("按电话");
mu3 = new JMenu("新增");
mi5 = new JMenuItem("新建联系人");
mu4 = new JMenu("帮助");
mi6 = new JMenuItem("关于");
mi7 = new JMenuItem("退出系统");
setJMenuBar(mb);
mb.add(mu1);
mu1.add(mi1);
mu1.add(mi2);
mb.add(mu2);
mu2.add(mi3);
mu2.add(mi4);
mb.add(mu3);
mu3.add(mi5);
mb.add(mu4);
mu4.add(mi6);
mu4.add(mi7);
lb.setForeground(Color.black);
pn.add(lb);
lt = new JList(dm);
lt.setSelectionForeground(Color.blue); // 选中后的字体颜色
lt.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JScrollPane sp = new JScrollPane(lt);
ImageIcon icon = new Ima
address_book.zip
版权申诉
5星 · 超过95%的资源 165 浏览量
2020-12-04
21:28:29
上传
评论 2
收藏 561KB ZIP 举报
狂野小青年
- 粉丝: 6748
- 资源: 28
最新资源
- main.c
- Unity 创建快捷方式自动启动
- 一分钟一条原创视频,蹭热点撸收益,条条爆款,狂撸各大平台,轻松日入1000+-教程网盘链接提取码下载 .txt
- 51单片机实现万年历,包括闹钟的设置与秒表功能(汇编)
- STM32单片机FPGA毕设电路原理论文报告铁合金电炉单片机电力监控系统的研究
- STM32单片机FPGA毕设电路原理论文报告贴片元件封装机的智能控制系统设计
- STM32单片机FPGA毕设电路原理论文报告体育高考投篮自动测试系统的设计与实现
- STM32单片机FPGA毕设电路原理论文报告提高放疗精度的单片机控制方法
- C++ matplot学习及demo实操
- STM32单片机FPGA毕设电路原理论文报告提高单晶炉加热电源控制电路精度的研究
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页