好友信息管理系统

java 同时被 2 个专栏收录
2 篇文章 0 订阅
1 篇文章 0 订阅

好友

  • 设计要点:设计并编程实现一个好友信息管理的小系统。系统应包含每位好友的全部信息,包括姓名、性别、生日、爱好、联系方式、性格特点等。系统实现对好友信息进行增、删、改、查、生日提醒、统计计算等功能。
  • 题目要求
    题目要求
  • 需求分析
        本阶段是整个软件开发过程中最重要的环节。通过了解实际运行的系统或与用户交谈,明确系统要完成的任务是什么。
        本次课程设计主要:开发一个简易的好友信息管理系统,首要任务是完成增、删、改、查的基本操作,如有余力的情况下可以考虑生日提醒,统计分析之类的加分项!
    该程序主要功能需求如下:
    1. 用户登录
        用户输入自己的用户名及密码登录到好友管理系统中,如果登陆成功,进入到管理系统的页面,如果登录失败,则提示重新输入密码。
    2. 添加记录
        用户可以通过添加按钮添加已存数据库之外的新的好友记录,点击添加记录按钮后,系统将跳出新窗口,用来填写新记录的信息,添加完成后点击完成按钮,窗口调回好友信息管理系统主页面。
    3. 删除记录
        首先用户通过查询功能找到要删除的记录,选定记录后,点击删除记录按钮删除该记录。
    4. 显示所有记录
        点击查询按钮,直接显示出所有的好友信息记录,也可以按照不同的类别,将记录显示出来。(选做)
    5. 修改记录
        首先用户通过查询功能找到要修改的记录,选定记录后,点击修改记录按钮修改该记录。
    6. 查询记录
        用户选定查询的类别,输入查询的信息,点击查询按钮,将把用户的信息显示到查询框下的文本框中。
    7. 备份记录
        通过点击备份按钮,系统将自动的把用户的所有记录信息打包备份。(选做)
    8. 退出
        当用户不在对通信录进行操作的时候,可以通过点击退出按钮退出系统。

    另外如果想要得到更好的成绩,还需要考虑如何实现好友生日的提醒,以及一份让人眼前一亮的小功能。

  • 系统文件使用说明
        打开程序,点击注册按钮进行注册,注册成功后再进行登陆。用户名和密码要对应。在此界面右下角有时间显示。
        登陆成功后先弹出一个窗口提醒好友生日,点击确定会显示主窗口。点击查询按钮会显示好友信息,右上角有两个菜单。文件菜单有保存和打开,编辑菜单有修改,增添,删除,统计等功能。
        在查询文本框中输入好友信息可进行查询操作,在编辑菜单中可用修改来更改好友信息,可用添加来添加好友,可用统计来统计好友个数与男女个数,可用删除来删除好友。进行操作后,需要再次点击查询按钮来更新界面。

  • 测试数据与结果

    用户点击登陆或注册按钮进入系统,已有用户可直接登录
图一
    生日提醒功能提醒好友生日
图二
    点击查询按钮显示所有数据
图三
    点击编辑菜单添加好友信息 点击完成按钮完成添加
图四
    点击编辑菜单进行好友删除 点击完成按钮完成删除
图五
    点击编辑菜单进行修改信息 点击完成按钮完成修改
图六
    点击编辑菜单进行统计 弹出窗口显示好友数量
图七
    用户注册界面 点击注册按钮完成注册
图八

  • 详细设计与实现
    用户登陆窗口
        用户输入自己的用户名及密码登录到好友管理系统中,如果登陆成功,进入到管理系统的页面,如果登录失败,则提示重新输入密码。
class MyWindow extends JFrame{
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn = DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo1");
rs.moveToInsertRow();
String a_t1=t1.getText().toString();
String a_t2=new String (t2.getPassword());
while(rs.next()) {
if(a_t1.equals(rs.getString(2))&&a_t2.equals(rs.getString(3))){ 
Login w2=new Login("好友信息管理系统");
dispose();flag=1;
w2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
JOptionPane.showConfirmDialog(new JFrame().getContentPane(), "是否保存?", "系统信息",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);}});}
else if(t1.getText().length()==0) {JOptionPane.showMessageDialog(null, "请输入账号", "Warning",JOptionPane.ERROR_MESSAGE);flag=2; break;}
else if(t2.getPassword().length==0) {JOptionPane.showMessageDialog(null, "请输入密码", "Warning",JOptionPane.ERROR_MESSAGE); flag=3;break;}}
if(flag==0) {JOptionPane.showMessageDialog(null, "您输入的账号或密码有误,请重新输入!", "Warning",JOptionPane.ERROR_MESSAGE);}
try{rs.insertRow();}catch(Exception e6){};
conn.close();} 
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}}};

  • 用户注册窗口

    若用户第一次使用,需要先通过注册再来进行登陆操作

ActionListener a2=new ActionListener() {
public void actionPerformed(ActionEvent e) {
Register w1=new Register("注册系统");
setEnabled(false);
w1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setEnabled(true); }});}};
class Register extends JFrame{
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = "jdbc:Access:///D:/demoTable.accdb"; 
try {Class.forName("com.hxtt.sql.access.AccessDriver"); 
Connection conn =DriverManager.getConnection(url); 
Statement stat = conn.createStatement();
stat =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo1");
rs.moveToInsertRow();
String a_t1=t1.getText().toString();
String a_t2=new String (t2.getPassword());
String a_t3=new String (t3.getPassword());
while(rs.next()) {
if(a_t1.equals(rs.getString(2))) {flag=1;}}
if(flag==1) {JOptionPane.showMessageDialog(null, "账户已存在!", "Warning",JOptionPane.ERROR_MESSAGE);}
rs.moveToInsertRow();
if(t1.getText().length()==0||t2.getPassword().length==0||t3.getPassword().length==0)
{JOptionPane.showMessageDialog(null, "内容不可以为空", "Warning",JOptionPane.ERROR_MESSAGE); }
else if(a_t2.equals(a_t3)&&flag==0){
JOptionPane.showMessageDialog(null, "注册成功!╮(╯▽╰)╭", "Success",JOptionPane.PLAIN_MESSAGE);
rs.updateString(2,a_t1);
rs.updateString(3,a_t2);}
else if
(Integer.parseInt(a_t2)!=Integer.parseInt(a_t3)&&flag==0)
{JOptionPane.showMessageDialog(null, "密码输入不一致,请重新输入", "Warning",JOptionPane.ERROR_MESSAGE);}
try{rs.insertRow();}catch(Exception e6){};conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}}};

  • 登陆主窗口
        主要显示数据、菜单的界面
class Login extends JFrame{
Box v1=Box.createVerticalBox();
JPanel jp=new JPanel();
JButton b1;JMenuBar mb;JMenu m1,m2;
JMenuItem item1,item2;
JMenuItem item3,item4,item5,item6;
JLabel l1=new JLabel("查找学生");
JTextField t1=new JTextField();
JTextArea ta1=new JTextArea();JTable table;
JScrollPane jsp;Object[][] a;
Object[] name={"序号","姓名","性别","生日","爱好","联系方式","性格特点"};
DefaultTableModel model; 
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
Add w3=new Add("添加好友信息");}};
ActionListener a2=new ActionListener() {
public void actionPerformed(ActionEvent e) {
Delete w4=new Delete("删除好友信息");}};
ActionListener a3=new ActionListener() {
public void actionPerformed(ActionEvent e) {
Revise w5=new Revise("修改好友信息");}};
ActionListener a4=new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showConfirmDialog(new JFrame().getContentPane(), "是否保存?", "系统信息",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);}};

  • 显示所有数据
        点击查询按钮,直接显示出所有的好友信息记录
ActionListener a5=new ActionListener() {
public void actionPerformed(ActionEvent e) {int i=0;
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn =DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo2");
rs.moveToInsertRow();rs.last();
int lastNumber=rs.getRow();
a=new Object[lastNumber][7];int k=0;
rs.beforeFirst();
if(t1.getText().length()==0) {
while(rs.next()) {
a[k][0]=rs.getString(1);……
a[k][6]=rs.getString(7);k++;}
table=new JTable(a,name);
table.setEnabled(false); 
table.setRowHeight(28);
add(new JScrollPane(table),BorderLayout.CENTER);
validate();}
String a_t1=t1.getText().toString();

  • 姓名查找
        用户选定查询的类别,输入查询的信息,点击查询按钮,将把用户的信息显示到查询框下的文本框中。(在此只展示姓名的查询方法)
while(rs.next()) {
if(a_t1.equals(rs.getString("姓名"))&&a_t1.length()!=0){
a[i][0]=rs.getString(1);……
a[i][6]=rs.getString(7);i++;
table=new JTable(a,name);
table.setEnabled(false); 
table.setRowHeight(28);
add(new JScrollPane(table),BorderLayout.CENTER);
validate();}}
try{rs.insertRow();}catch(Exception e6){};
conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}}};
ActionListener a6=new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i=0,j=0;
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn =DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo2");
rs.moveToInsertRow();
String a_t1="男";String a_t2="女";
rs.beforeFirst();
while(rs.next()) {
if(a_t1.equals(rs.getString("性别"))){i++;}
if(a_t2.equals(rs.getString("性别"))){j++;}}rs.last();
int lastNumber=rs.getRow();
JOptionPane.showMessageDialog(null,"您一共存有"+lastNumber+"个好友的信息,其中男生有"+i+"个,女生有"+j+"个。");
try{rs.insertRow();}catch(Exception e6){};
conn.close();} 
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}}};
Login(String s){setTitle(s);
Date time1=new Date();
SimpleDateFormat s1=new SimpleDateFormat("MM-dd");
mb=new JMenuBar();
m1=new JMenu("文件");
m2=new JMenu("编辑");
b1=new JButton("查找");
item1=new JMenuItem("打开",new ImageIcon("open.gif"));……
item6=new JMenuItem("统计");
item1.setAccelerator(KeyStroke.getKeyStroke('0'));……
item6.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
b1.registerKeyboardAction(a5, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),JComponent.WHEN_IN_FOCUSED_WINDOW);

  • 好友生日提醒(伪)
        用于提醒用户好友生日的小程序
if(s1.format(time1).equals(rs.getString(4))) {
if(k==i) {JOptionPane.showMessageDialog(null, "您的好友"+rs.getString(2)+"今天过生日哟!╮(╯▽╰)╭"); }}}
table=new JTable(a,name);
table.setEnabled(false); 
table.setRowHeight(28);
getContentPane().removeAll();
add(control,BorderLayout.SOUTH);
add(new JScrollPane(table),BorderLayout.CENTER);validate();
try{rs.insertRow();}catch(Exception e6){};conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}}}

  • 添加好友信息
        用户可以添加已存数据库之外的新的好友记录,点击添加记录菜单后,系统将跳出新窗口,用来填写新记录的信息,添加完成后点击完成按钮,窗口调回好友信息管理系统主页面。
class Add extends JFrame{
JButton b1=new JButton("完成");
JLabel l1=new JLabel("(*)姓名:"),……
l6=new JLabel("性格特点:"),
l7=new JLabel("注:*为必填项");
JTextField t1=new JTextField(20),……
t6=new JTextField(20);
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn =DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat =conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo2");
rs.moveToInsertRow();
String a_t1=t1.getText().toString();……
String a_t6=t6.getText().toString();
rs.updateString("姓名",a_t1);……
rs.updateString("性格特点",a_t6);
t1.setText("添加成功!");
try{rs.insertRow();}catch(Exception e6){};
conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}};};

  • 删除好友信息
         首先用户通过查询功能找到要删除的记录,选定记录后,点击删除记录按钮删除该记录。
class Delete extends JFrame{
int i=0,flag=0;
JButton b1=new JButton("完成");
JLabel l1=new JLabel("序号"),
l2=new JLabel("姓名");
JTextField t1=new JTextField(20),
t2=new JTextField(20);
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn =DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo2");
rs.moveToInsertRow();
String a_t1=t1.getText().toString();
String a_t2=t2.getText().toString();
while(rs.next()) {i++;
if(a_t1.equals(rs.getString("序号"))&&a_t2.equals(rs.getString("姓"))) {
String a_t4=" ";rs.absolute(i);rs.updateString(2,a_t4);……
rs.updateString(7,a_t4);t1.setText("删除成功!");rs.updateRow();}
else if(a_t1!=rs.getString("序号")) {
if(a_t1.equals(rs.getString("序号"))) {flag=3;break;}else {flag=2;}}
else if(a_t1.equals(rs.getString("序号"))&&a_t2.equals(rs.getString("姓名"))==false) {flag=3;}}
if(flag==2) {t1.setText("序号错误!");}
else if(flag==3) {t2.setText("姓名错误!");}
try{rs.insertRow();}catch(Exception e6){};conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}};};

  • 修改好友信息
         首先用户通过查询功能找到要修改的记录,选定记录后,点击修改记录按钮修改该记录。
class Revise extends JFrame{
int i=0;
JButton b1=new JButton("完成");
JLabel l1=new JLabel("姓名:"),……
l7=new JLabel("序号:");
JTextField  t1=new JTextField(20),……
t7=new JTextField(20);
ActionListener a1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
String url = "jdbc:Access:///D:/demoTable.accdb";
try {Class.forName("com.hxtt.sql.access.AccessDriver");
Connection conn =DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stat.executeQuery("select * from demo2");
rs.moveToInsertRow();
String a_t1=t1.getText().toString();……
String a=t7.getText().toString();
while(rs.next()) {i++;
if(a.equals(rs.getString(1))) {
rs.absolute(i);
rs.updateString(2,a_t1);……
rs.updateString(7,a_t6);
t7.setText("修改成功!");
rs.updateRow();}}
try{rs.insertRow();}catch(Exception e6){};
conn.close();}
catch (ClassNotFoundException | SQLException e1) {
e1.printStackTrace();}};};

  • 源程序及系统文件使用说明
import java.io.UnsupportedEncodingException;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Example {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyWindow win=new MyWindow("好友管理系统");
	}
}
class MyWindow extends JFrame{
	int flag=0;
	Box v1,v2,v3,v4,v5;
	JButton b1=new JButton("登录");
	JButton b2=new JButton("注册");
	JLabel l=new JLabel("欢迎来到好友管理系统");
	JLabel l1=new JLabel("账号:");
	JLabel l2=new JLabel("密码: ");
	JTextField t1=new JTextField(16);
	JPasswordField t2= new JPasswordField(16);
	
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
//			t1.setText("请输入账号");
			
			String url = "jdbc:Access:///D:/demoTable.accdb";
			try {
			Class.forName("com.hxtt.sql.access.AccessDriver");
			Connection conn = DriverManager.getConnection(url);
			Statement stat = conn.createStatement();
			
            stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
			ResultSet rs=stat.executeQuery("select * from demo1");
			rs.moveToInsertRow();
			String a_t1=t1.getText().toString();
			String a_t2=new String (t2.getPassword());
			
			while(rs.next()) {
				if(a_t1.equals(rs.getString(2))&&a_t2.equals(rs.getString(3))){  //从rs中取出记录的password字段,和传入的参数pass做比较
					Login w2=new Login("好友信息管理系统");
					dispose();
					flag=1;
					w2.addWindowListener(new WindowAdapter() {  
						 //添加首界面的关闭事件:
							public void windowClosing(WindowEvent e) {  
						  //添加事件:
								JOptionPane.showConfirmDialog(new JFrame().getContentPane(), "是否保存?", "系统信息",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); 
						       }   
						   });
					
				}
				else if(t1.getText().length()==0) {JOptionPane.showMessageDialog(null, "请输入账号", "Warning",JOptionPane.ERROR_MESSAGE);flag=2; break;}
				else if(t2.getPassword().length==0) {JOptionPane.showMessageDialog(null, "请输入密码", "Warning",JOptionPane.ERROR_MESSAGE); flag=3;break;}
			}
			if(flag==0) {JOptionPane.showMessageDialog(null, "您输入的账号或密码有误,请重新输入!", "Warning",JOptionPane.ERROR_MESSAGE);}

				
			
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		}
		
	};
	ActionListener a2=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			Register w1=new Register("注册系统");
			setEnabled(false);
			w1.addWindowListener(new WindowAdapter() {  
			 //添加首界面的关闭事件:
				public void windowClosing(WindowEvent e) {  
			  //添加事件:
					setEnabled(true);//将主界面再设置为可操作的
			       }   
			   });
		}
	};
	MyWindow(String s){
		ImageIcon img1 = new ImageIcon("./src/p1.gif");          //相对路径获取图片         
		JLabel imgLabel = new JLabel(img1);                              //创建图片标签
        this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));//为标签设置为容器最底层;getLayeredPane()作用是为容器添加深度,允许组件互相重叠;Integer.MIN_VALUE最底层
        imgLabel.setSize(img1.getIconWidth(), img1.getIconHeight());
        Container cp=getContentPane(); //获取顶级容器
       ((JPanel)cp).setOpaque(false); //设置透明以使底层背景图片显示 
       cp.setLayout(null);
       
	  				
		
		t2.setEchoChar('*');
		setTitle(s);
		v5=Box.createHorizontalBox();
		v5.add(l);
		l.setFont(new Font("宋体",Font.PLAIN,30));
		
		
		//显示时间
		JPanel control=new JPanel(); //窗体底部面板
		control.setLayout(new BoxLayout(control,BoxLayout.X_AXIS)); //设置布局管理器
		final JLabel time=new JLabel("显示时间"); //显示时间标签
		Timer timer=new Timer();
		timer.schedule(new TimerTask() {
		public void run() {
		Date d=new Date();
		SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		time.setText(s.format(d));
		}
		}, 0, 1000);
//		time.setBorder(BorderFactory.createEtchedBorder()); //设置边框
		Component cop=(Component) Box.createHorizontalGlue(); //创建一个不可见的组件,该组件可沿水平方向扩展
		control.add(cop); //在面板中添加该不可见组件
		control.add(time); //在面板中添加时间标签		   
		control.setOpaque(false);
		
		v2=Box.createHorizontalBox();
		v2.add(l1);
		v2.add(Box.createHorizontalStrut(3));
		v2.add(t1);
		
		v3=Box.createHorizontalBox();
		v3.add(l2);
		v3.add(Box.createHorizontalStrut(10));
		v3.add(t2);
		
		v4=Box.createHorizontalBox();
		v4.add(Box.createHorizontalGlue());
		v4.add(b1);
		v4.add(Box.createHorizontalStrut(10));
		v4.add(b2);
		v4.add(Box.createHorizontalGlue());
		
		v1=Box.createVerticalBox();
		v1.add(Box.createVerticalStrut(80));
		v1.add(l);
		v1.add(Box.createVerticalStrut(30));
		v1.add(v2);
		v1.add(Box.createVerticalStrut(10));
		v1.add(v3);
		v1.add(Box.createVerticalStrut(20));
		v1.add(v4);
		v1.add(Box.createVerticalStrut(70));
		v1.add(control,BorderLayout.SOUTH); //获取窗口的内容面板,将自定义面板添加进去
		
		setLayout(new FlowLayout());
		add(v1);
		validate();
		setSize(650,433);
		setVisible(true);
		setResizable(false);
		this.setLocationRelativeTo(null);
		b1.addActionListener(a1);
		b2.addActionListener(a2);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
	}
}
//注册窗口
class Register extends JFrame{
	int flag=0;
	Box v1,v2,v3,v4,v5;
	JLabel l1=new JLabel("新账号:");
	JLabel l2=new JLabel("密码:");
	JLabel l3=new JLabel("确认:");
	JTextField t1=new JTextField(16);
	JPasswordField t2=new JPasswordField(16),t3=new JPasswordField(16);
	JButton b1=new JButton("完 成 注 册");
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			
			// url表示需要连接的数据源的位置,此时使用的是JDBC-ODBC桥的连接方式,url是"jdbc:odbc:数据源名"
			String url = "jdbc:Access:///D:/demoTable.accdb";//数据库连接字符串
			try {
			Class.forName("com.hxtt.sql.access.AccessDriver");//加载驱动类,不同数据库软件驱动类不同
			Connection conn =DriverManager.getConnection(url);//声明连接对象,用类DriverManager调用它的静态方法getConnection创建这个连接
			Statement stat = conn.createStatement();//创建执行数据库操作对象
            stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rs=stat.executeQuery("select * from demo1");
            
			rs.moveToInsertRow();
			String a_t1=t1.getText().toString();
			String a_t2=new String (t2.getPassword());
			String a_t3=new String (t3.getPassword());
			
			while(rs.next()) {
				if(a_t1.equals(rs.getString(2))) {flag=1;}
			}
			if(flag==1) {JOptionPane.showMessageDialog(null, "账户已存在!", "Warning",JOptionPane.ERROR_MESSAGE);}
			rs.moveToInsertRow();//rs.next()改变了游标的位置,通过这个回到插入行
			
			if(t1.getText().length()==0||t2.getPassword().length==0||t3.getPassword().length==0)
			 {JOptionPane.showMessageDialog(null, "内容不可以为空", "Warning",JOptionPane.ERROR_MESSAGE); }
			else if(a_t2.equals(a_t3)&&flag==0){
				JOptionPane.showMessageDialog(null, "注册成功!╮(╯▽╰)╭", "Success",JOptionPane.PLAIN_MESSAGE);
				
				rs.updateString(2,a_t1);//向第二列字段填入数据
			    rs.updateString(3,a_t2);//向第三列字段填入数据 	
			 }
			else if(Integer.parseInt(a_t2)!=Integer.parseInt(a_t3)&&flag==0)
			{JOptionPane.showMessageDialog(null, "密码输入不一致,请重新输入", "Warning",JOptionPane.ERROR_MESSAGE);}
			 
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} 
			catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			}
	}
};

	Register(String s){
		setTitle(s);
		v1=Box.createHorizontalBox();
		v1.add(l1);
		l1.setFont(new Font("黑体",Font.PLAIN,20));
		v1.add(Box.createHorizontalStrut(0));
		v1.add(t1);
		
		v2=Box.createHorizontalBox();
		v2.add(l2);
		l2.setFont(new Font("黑体",Font.PLAIN,20));
		v2.add(Box.createHorizontalStrut(20));
		v2.add(t2);

		v3=Box.createHorizontalBox();
		v3.add(l3);
		l3.setFont(new Font("黑体",Font.PLAIN,20));
		v3.add(Box.createHorizontalStrut(20));
		v3.add(t3);
		
		v4=Box.createHorizontalBox();
		v4.add(b1);
		
		v5=Box.createVerticalBox();
		v5.add(Box.createVerticalStrut(80));
		v5.add(v1);
		v5.add(Box.createVerticalStrut(10));
		v5.add(v2);
		v5.add(Box.createVerticalStrut(10));
		v5.add(v3);
		v5.add(Box.createVerticalStrut(10));
		v5.add(v4);
				
		setLayout(new FlowLayout());
		add(v5);
		validate();
		setSize(650,400);
		setVisible(true);
		setResizable(false);
		this.setLocationRelativeTo(null);
		b1.addActionListener(a1);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		
		
	}
}

//登录主窗口
class Login extends JFrame{
	Box v1=Box.createVerticalBox();
	JPanel jp=new JPanel();
	JButton b1;
	JMenuBar mb;
	JMenu m1,m2;
	JMenuItem item1,item2;
	JMenuItem item3,item4,item5,item6;
	JLabel l1=new JLabel("                                                                 查找学生");
	JTextField t1=new JTextField();
	JTextArea ta1=new JTextArea();
	JTable table;
	JScrollPane jsp;
	Object[][] a;
	Object[] name={"序号","姓名","性别","生日","爱好","联系方式","性格特点"};
	DefaultTableModel model;//用DefaultTableModel类创建表格
	
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			Add w3=new Add("添加好友信息"); 
		}
	};
	ActionListener a2=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			Delete w4=new Delete("删除好友信息"); 
		}
	};
	ActionListener a3=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			Revise w5=new Revise("修改好友信息"); 
		}
	};
	ActionListener a4=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			JOptionPane.showConfirmDialog(new JFrame().getContentPane(), "是否保存?", "系统信息",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); 
		}
	};
	
//显示所有数据
ActionListener a5=new ActionListener() {
	public void actionPerformed(ActionEvent e) {
		//当输入框为0时,点击按钮主页面显示所有数据
		int i=0;
		String url = "jdbc:Access:///D:/demoTable.accdb";
			try {
				Class.forName("com.hxtt.sql.access.AccessDriver");
				Connection conn =DriverManager.getConnection(url);
				Statement stat = conn.createStatement();
		        stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
		        
		        ResultSet rs=stat.executeQuery("select * from demo2");
				rs.moveToInsertRow();
				rs.last();//指针移到最后一条后面
				int lastNumber=rs.getRow();
				a=new Object[lastNumber][7];
				int k=0;
				rs.beforeFirst();//指针移到第一条前面
				if(t1.getText().length()==0) {
				while(rs.next()) {
					a[k][0]=rs.getString(1);
					a[k][1]=rs.getString(2);
					a[k][2]=rs.getString(3);
					a[k][3]=rs.getString(4);
					a[k][4]=rs.getString(5);
					a[k][5]=rs.getString(6);
					a[k][6]=rs.getString(7);
					k++;
					}
				table=new JTable(a,name);
				table.setEnabled(false);//设置表格为不可编辑
				table.setRowHeight(28);
//				 getContentPane().removeAll();
				 add(new JScrollPane(table),BorderLayout.CENTER);
				 validate();
				}
				
				String a_t1=t1.getText().toString();
				//通过姓名查找
				while(rs.next()) {
					if(a_t1.equals(rs.getString("姓名"))&&a_t1.length()!=0){
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();
					}
				}
				//性别查找
				rs.beforeFirst();
				while(rs.next()) {
					if(a_t1.equals(rs.getString("性别"))&&a_t1.length()!=0){ 
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
						
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();

					}
					
				}
				//生日查询
				rs.beforeFirst();
				while(rs.next()) {
					if(a_t1.equals(rs.getString("生日"))&&a_t1.length()!=0){
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();
					}
				}
				//爱好查询
				rs.beforeFirst();
				while(rs.next()) {
					if(a_t1.equals(rs.getString("爱好"))&&a_t1.length()!=0){
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();
					}
				}
				//联系方式查询
				rs.beforeFirst();
				while(rs.next()) {
					if(a_t1.equals(rs.getString("联系方式"))&&a_t1.length()!=0){
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();
					}
				}
				//性格特点
				rs.beforeFirst();
				while(rs.next()) {
					if(a_t1.equals(rs.getString("性格特点"))&&a_t1.length()!=0){
						a[i][0]=rs.getString(1);
						a[i][1]=rs.getString(2);
						a[i][2]=rs.getString(3);
						a[i][3]=rs.getString(4);
						a[i][4]=rs.getString(5);
						a[i][5]=rs.getString(6);
						a[i][6]=rs.getString(7);
						i++;
						table=new JTable(a,name);
						table.setEnabled(false);//设置表格为不可编辑
						table.setRowHeight(28);
//						 getContentPane().removeAll();
						 add(new JScrollPane(table),BorderLayout.CENTER);
						 validate();
					}
				}
				 try{rs.insertRow();}catch(Exception e6){};
					conn.close();
				} 
					catch (ClassNotFoundException | SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		}
};
ActionListener a6=new ActionListener() {
	public void actionPerformed(ActionEvent e) {
		int i=0,j=0;
		String url = "jdbc:Access:///D:/demoTable.accdb";
		try {
			Class.forName("com.hxtt.sql.access.AccessDriver");
			Connection conn =DriverManager.getConnection(url);
			Statement stat = conn.createStatement();
	        stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
	        
	        ResultSet rs=stat.executeQuery("select * from demo2");
			rs.moveToInsertRow();
			
			String a_t1="男";
			String a_t2="女";
			rs.beforeFirst();
			while(rs.next()) {
				if(a_t1.equals(rs.getString("性别"))){i++;}
				if(a_t2.equals(rs.getString("性别"))){j++;}
				}
			rs.last();//指针移到最后一条后面
			int lastNumber=rs.getRow();
			JOptionPane.showMessageDialog(null,"您一共存有"+lastNumber+"个好友的信息,其中男生有"+i+"个,女生有"+j+"个。"); 
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			}

		}	
};
	Login(String s){
		setTitle(s);
		
		Date time1=new Date();
		SimpleDateFormat s1=new SimpleDateFormat("MM-dd");
		mb=new JMenuBar();
		m1=new JMenu("文件");
		m2=new JMenu("编辑");
		b1=new JButton("查找");
		item1=new JMenuItem("打开",new ImageIcon("open.gif"));
		item2=new JMenuItem("保存",new ImageIcon("save.gif"));
		item3=new JMenuItem("添加");
		item4=new JMenuItem("删除");
		item5=new JMenuItem("修改");
		item6=new JMenuItem("统计");
		item1.setAccelerator(KeyStroke.getKeyStroke('0'));
		item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		item3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
		item4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
		item5.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
		item6.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
		b1.registerKeyboardAction(a5, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),JComponent.WHEN_IN_FOCUSED_WINDOW);
		
		//显示时间
		JPanel control=new JPanel(); //窗体底部面板
		control.setLayout(new BoxLayout(control,BoxLayout.X_AXIS)); //设置布局管理器
		final JLabel time=new JLabel("显示时间"); //显示时间标签
		Timer timer=new Timer();
		timer.schedule(new TimerTask() {
		public void run() {
		Date d=new Date();
		SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		time.setText(s.format(d));
		}
		}, 0, 1000);
		
//		time.setBorder(BorderFactory.createEtchedBorder()); //设置边框
		Component cop=(Component) Box.createHorizontalGlue(); //创建一个不可见的组件,该组件可沿水平方向扩展
		control.add(cop); //在面板中添加该不可见组件
		control.add(time); //在面板中添加时间标签	
		
		m1.add(item1);
		m1.addSeparator();
		m1.add(item2);
		m2.add(item3);
		m2.addSeparator();
		m2.add(item4);
		m2.addSeparator();
		m2.add(item5);
		m2.addSeparator();
		m2.add(item6);
		mb.add(m1);
		mb.add(m2);
		mb.add(l1);
		mb.add(t1);
		mb.add(b1);
		
		jsp=new JScrollPane(table);		
		jsp.setPreferredSize(new Dimension(980,500));//设置jsp的长和宽
		setJMenuBar(mb);
		v1.add(jsp);
		v1.add(ta1);
		jp.add(v1);
		jp.add(control,BorderLayout.SOUTH); //获取窗口的内容面板,将自定义面板添加进去
		jp.setLayout(new FlowLayout());
		add(jp);

		b1.addActionListener(a5);
		item3.addActionListener(a1);
		item4.addActionListener(a2);
		item5.addActionListener(a3);
		item6.addActionListener(a6);
		item2.addActionListener(a4);
		
		
		setSize(1000,600);
		setVisible(true);
		setResizable(false);
		this.setLocationRelativeTo(null);
		validate();
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		String url = "jdbc:Access:///D:/demoTable.accdb";
		try {
		Class.forName("com.hxtt.sql.access.AccessDriver");
		Connection conn =DriverManager.getConnection(url);
		Statement stat = conn.createStatement();
        stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        
        ResultSet rs=stat.executeQuery("select * from demo2");
		rs.moveToInsertRow();
		
		rs.last();//指针移到最后一条后面
		int lastNumber=rs.getRow();
		a=new Object[lastNumber][7];
		int k=0,i=0;
		rs.beforeFirst();//指针移到第一条前面
		while(rs.next()) {
			a[k][0]=rs.getString(1);
			a[k][1]=rs.getString(2);
			a[k][2]=rs.getString(3);
			a[k][3]=rs.getString(4);
			a[k][4]=rs.getString(5);
			a[k][5]=rs.getString(6);
			a[k][6]=rs.getString(7);
			k++;i++;
			//好友生日提醒(伪)
			if(s1.format(time1).equals(rs.getString(4))) {
				if(k==i) {JOptionPane.showMessageDialog(null, "您的好友"+rs.getString(2)+"今天过生日哟!╮(╯▽╰)╭"); }
				}
			}
		table=new JTable(a,name);
		table.setEnabled(false);//设置表格为不可编辑
		table.setRowHeight(28);
		 getContentPane().removeAll();
		 add(control,BorderLayout.SOUTH);
		 add(new JScrollPane(table),BorderLayout.CENTER);
		 validate();
		
	    try{rs.insertRow();}catch(Exception e6){};
		conn.close();
		} 
		catch (ClassNotFoundException | SQLException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
		}
	}
}
//添加好友信息
class Add extends JFrame{
	Box v1,v2,v3,v4,v5,v6,v7;
	JButton b1=new JButton("完成");
	JLabel l1=new JLabel("(*)姓名:"),
			l2=new JLabel("(*)性别:"),
			l3=new JLabel("(*)生日:"),
			l4=new JLabel("   爱好:"),
			l5=new JLabel("联系方式:"),
			l6=new JLabel("性格特点:"),
			l7=new JLabel("注:*为必填项");
	JTextField t1=new JTextField(20),
				t2=new JTextField(20),
				t3=new JTextField(20),
				t4=new JTextField(20),
				t5=new JTextField(20),
				t6=new JTextField(20);
	
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			String url = "jdbc:Access:///D:/demoTable.accdb";
			try {
			Class.forName("com.hxtt.sql.access.AccessDriver");
			Connection conn =DriverManager.getConnection(url);
			Statement stat = conn.createStatement();
            stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            
            ResultSet rs=stat.executeQuery("select * from demo2");
			rs.moveToInsertRow();
			String a_t1=t1.getText().toString();
			String a_t2=t2.getText().toString();
			String a_t3=t3.getText().toString();
			String a_t4=t4.getText().toString();
			String a_t5=t5.getText().toString();
			String a_t6=t6.getText().toString();
			
			rs.updateString("姓名",a_t1);
		    rs.updateString("性别",a_t2);
		    rs.updateString("生日",a_t3);
		    rs.updateString("爱好",a_t4);
		    rs.updateString("联系方式",a_t5);
		    rs.updateString("性格特点",a_t6);
			 
		    t1.setText("添加成功!");
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} 
			catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	};
	};
	
	
	Add(String s){
		setTitle(s);
		v1=Box.createHorizontalBox();
		v1.add(l1);
		l1.setFont(new Font("黑体",Font.PLAIN,20));
		v1.add(Box.createHorizontalStrut(10));
		v1.add(t1);
		
		v2=Box.createHorizontalBox();
		v2.add(l2);
		l2.setFont(new Font("黑体",Font.PLAIN,20));
		v2.add(Box.createHorizontalStrut(10));
		v2.add(t2);
		
		v3=Box.createHorizontalBox();
		v3.add(l3);
		l3.setFont(new Font("黑体",Font.PLAIN,20));
		v3.add(Box.createHorizontalStrut(10));
		v3.add(t3);

		v4=Box.createHorizontalBox();
		v4.add(l4);
		l4.setFont(new Font("黑体",Font.PLAIN,20));
		v4.add(Box.createHorizontalStrut(10));
		v4.add(t4);

		v5=Box.createHorizontalBox();
		v5.add(l5);
		l5.setFont(new Font("黑体",Font.PLAIN,20));
		v5.add(Box.createHorizontalStrut(0));
		v5.add(t5);

		v6=Box.createHorizontalBox();
		v6.add(l6);
		l6.setFont(new Font("黑体",Font.PLAIN,20));
		v1.add(Box.createHorizontalStrut(10));
		v6.add(t6);
		
		v7=Box.createVerticalBox();
		v7.add(Box.createVerticalStrut(30));
		v7.add(v1);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v2);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v3);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v4);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v5);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v6);
		v7.add(Box.createVerticalStrut(25));
		v7.add(l7);
		l7.setFont(new Font("黑体",Font.PLAIN,20));
		l7.setForeground(Color.red);
		v7.add(Box.createVerticalStrut(15));
		v7.add(b1);
		setLayout(new FlowLayout());
		add(v7);
		setSize(400,400);
		setVisible(true);
		setResizable(false);
		b1.addActionListener(a1);
		this.setLocationRelativeTo(null);
	}
}
//删除好友信息
class Delete extends JFrame{
	int i=0,flag=0;
	Box v1,v2,v3;
	JButton b1=new JButton("完成");
	JLabel l1=new JLabel("序号"),
			l2=new JLabel("姓名");
	JTextField t1=new JTextField(20),
				t2=new JTextField(20);
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			String url = "jdbc:Access:///D:/demoTable.accdb";
			try {
			Class.forName("com.hxtt.sql.access.AccessDriver");
			Connection conn =DriverManager.getConnection(url);
			Statement stat = conn.createStatement();
			stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            
            ResultSet rs=stat.executeQuery("select * from demo2");
			rs.moveToInsertRow();
			String a_t1=t1.getText().toString();
			String a_t2=t2.getText().toString();
			while(rs.next()) {
				i++;
				if(a_t1.equals(rs.getString("序号"))&&a_t2.equals(rs.getString("姓名"))) {
					String a_t4=" ";
					rs.absolute(i);
					rs.updateString(2,a_t4);
					rs.updateString(3,a_t4);
					rs.updateString(4,a_t4);
					rs.updateString(5,a_t4);
					rs.updateString(6,a_t4);
					rs.updateString(7,a_t4);
					t1.setText("删除成功!");
					rs.updateRow();
				}
				else if(a_t1!=rs.getString("序号")) {
					if(a_t1.equals(rs.getString("序号"))) {flag=3;break;}
					else {flag=2;}
					}
				else if(a_t1.equals(rs.getString("序号"))&&a_t2.equals(rs.getString("姓名"))==false) {flag=3;}
				
			}
			if(flag==2) {t1.setText("序号错误!");}
			else if(flag==3) {t2.setText("姓名错误!");}
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} 
			catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			}
		};

	};
	
	
	Delete(String s){
		setTitle(s);
		v1=Box.createHorizontalBox();
		v1.add(l1);
		v1.add(Box.createHorizontalStrut(10));
		v1.add(t1);
		
		v2=Box.createHorizontalBox();
		v2.add(l2);
		v2.add(Box.createHorizontalStrut(10));
		v2.add(t2);
		
		v3=Box.createVerticalBox();
		v3.add(Box.createVerticalStrut(50));
		v3.add(v1);
		v3.add(Box.createVerticalStrut(10));
		v3.add(v2);
		v3.add(Box.createVerticalStrut(10));
		v3.add(b1);
		setLayout(new FlowLayout());
		add(v3);
		
		setSize(400,250);
		setVisible(true);
		setResizable(false);
		b1.addActionListener(a1);
		this.setLocationRelativeTo(null);
	}
}
//修改好友信息
class Revise extends JFrame{
	int i=0;
	Box v1,v2,v3,v4,v5,v6,v7,v8;
	JButton b1=new JButton("完成");
	JLabel l1=new JLabel("   姓名:"),
			l2=new JLabel("   性别:"),
			l3=new JLabel("   生日:"),
			l4=new JLabel("   爱好:"),
			l5=new JLabel("联系方式:"),
			l6=new JLabel("性格特点:"),	
			l7=new JLabel("   序号:");
	
	
	JTextField  t1=new JTextField(20),
				t2=new JTextField(20),
				t3=new JTextField(20),
				t4=new JTextField(20),
				t5=new JTextField(20),
				t6=new JTextField(20),
				t7=new JTextField(20);
	
	ActionListener a1=new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			
			String url = "jdbc:Access:///D:/demoTable.accdb";
			try {
			Class.forName("com.hxtt.sql.access.AccessDriver");
			Connection conn =DriverManager.getConnection(url);
			Statement stat = conn.createStatement();
            stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            
            ResultSet rs=stat.executeQuery("select * from demo2");
			rs.moveToInsertRow();
			String a_t1=t1.getText().toString();
			String a_t2=t2.getText().toString();
			String a_t3=t3.getText().toString();
			String a_t4=t4.getText().toString();
			String a_t5=t5.getText().toString();
			String a_t6=t6.getText().toString();
			String a=t7.getText().toString();
			while(rs.next()) {
				i++;
				if(a.equals(rs.getString(1))) {
					rs.absolute(i);
					rs.updateString(2,a_t1);
					rs.updateString(3,a_t2);
					rs.updateString(4,a_t3);
					rs.updateString(5,a_t4);
					rs.updateString(6,a_t5);
					rs.updateString(7,a_t6);
					t7.setText("修改成功!");
					rs.updateRow();
				}
			}
			
		    try{rs.insertRow();}catch(Exception e6){};
			conn.close();
			} 
			catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	};
		};


	
	Revise(String s){
		setTitle(s);
		v8=Box.createHorizontalBox();
		v8.add(l7);
		l7.setFont(new Font("黑体",Font.PLAIN,20));
		v8.add(Box.createHorizontalStrut(10));
		v8.add(t7);
		
		v1=Box.createHorizontalBox();
		v1.add(l1);
		l1.setFont(new Font("黑体",Font.PLAIN,20));
		v1.add(Box.createHorizontalStrut(10));
		v1.add(t1);
		
		v2=Box.createHorizontalBox();
		v2.add(l2);
		l2.setFont(new Font("黑体",Font.PLAIN,20));
		v2.add(Box.createHorizontalStrut(10));
		v2.add(t2);
		
		v3=Box.createHorizontalBox();
		v3.add(l3);
		l3.setFont(new Font("黑体",Font.PLAIN,20));
		v3.add(Box.createHorizontalStrut(10));
		v3.add(t3);

		v4=Box.createHorizontalBox();
		v4.add(l4);
		l4.setFont(new Font("黑体",Font.PLAIN,20));
		v4.add(Box.createHorizontalStrut(10));
		v4.add(t4);

		v5=Box.createHorizontalBox();
		v5.add(l5);
		l5.setFont(new Font("黑体",Font.PLAIN,20));
		v5.add(Box.createHorizontalStrut(0));
		v5.add(t5);

		v6=Box.createHorizontalBox();
		v6.add(l6);
		l6.setFont(new Font("黑体",Font.PLAIN,20));
		v1.add(Box.createHorizontalStrut(10));
		v6.add(t6);
		
		v7=Box.createVerticalBox();
		v7.add(Box.createVerticalStrut(20));
		v7.add(v8);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v1);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v2);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v3);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v4);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v5);
		v7.add(Box.createVerticalStrut(10));
		v7.add(v6);
		v7.add(Box.createVerticalStrut(30));
		v7.add(b1);
		setLayout(new FlowLayout());
		add(v7);
		setSize(400,400);
		setVisible(true);
		setResizable(false);
		b1.addActionListener(a1);
		this.setLocationRelativeTo(null);

	}
}

  • 开发环境与开发工具
         - 开发环境
            操作系统:Windows 10
            运行环境:JDK 1.8
            选择依据:JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。

     - 开发工具 Eclipse Access
        选择依据
        Eclipse 是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准的插件集,包括Java开发工具(Java Development Kit,JDK)。Eclipse小巧,占用资源也少,速度快,功能强大。
        Access支持ODBC(开发数据库互连,Open Data Base Connectivity),利用Access强大的DDE(动态数据交换)和OLE(对象的联接和嵌入)特性,可以在一个数据表中嵌入位图、声音、Excel表格、Word文档,还可以建立动态的数据库报表和窗体等。

  • 3
    点赞
  • 0
    评论
  • 16
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:精致技术 设计师:CSDN官方博客 返回首页

打赏作者

TomLazy

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值