import java.awt.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
class DataWindow extends JFrame implements ActionListener
{
JFrame f;
JPanel p1,p2,p3;
FileDialog filedialog_save; //声明文件对话框
JTextField tf1,tf2;
JButton b1,b2,b3;
JLabel lb1,lb2;
DataWindow()
{
super("init");
this.setBounds(200,200,300,300);
this.setVisible(true);
tf1 = new JTextField(16);
tf1.setFont(new Font("",15,15));
tf2 = new JTextField(16);
tf2.setFont(new Font("",15,15));
b1 = new JButton("add");
b2 = new JButton("true");
b3 = new JButton("del");
JPanel p1 = new JPanel(),p2 = new JPanel(),p3 = new JPanel();//添加面板
lb1 = new JLabel("user:");
lb1.setFont(new Font("隶书",20,20));
lb2 = new JLabel("secret:");
lb2.setFont(new Font("隶书",20,20));
p1.setLayout(new GridLayout());
p1.add(lb1);
p1.add(tf1);
p1.add(lb2);
p1.add(tf2);
p2.setLayout(new FlowLayout());
p2.add("Left",b1);
p2.add("Center",b2);
p2.add("Right",b3);
this.setLayout(new BorderLayout());
this.add("North",p1);
this.add("South",p2);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
tf1.addActionListener(this);
tf2.addActionListener(this);
filedialog_save = new FileDialog(this,"保存文件对话框",FileDialog.SAVE);
filedialog_save.addWindowListener(new WindowAdapter() //对话框增加适配器
{
public void windowClosing(WindowEvent e)
{
filedialog_save.setVisible(false);
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0); }
});
}
public void actionPerformed(ActionEvent e) //实现按钮监听
{
if(e.getSource()==b2&&e.getSource()==tf1&&e.getSource()==tf2)
{
tf1.setText("");
tf2.setText("");
if(tf1.getText().equals("")||tf2.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"对象不能为空!","警告",
JOptionPane.WARNING_MESSAGE);
}
else{
try{ Listwords(); }
catch(SQLException ee){ }
}
}
else if(e.getSource()==b1)
{
Add add= new Add(); //AddWin是添加窗口的类
}
else if(e.getSource()==b3)
{
Del del = new Del(); //DelWin是删除窗口的类
}
}
public void Listwords() throws SQLException //实现查询功能
{
String cname,ename;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
//建立桥接器
Connection Ex1Con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=user\\user.mdb","","");
Statement Ex1Stmt = Ex1Con.createStatement();
if(lb1.getText().equals("user:")&&lb2.getText().equals("secret:"))
{
ResultSet rs = Ex1Stmt.executeQuery("SELECT * FROM 表1");
while( rs.next())
{
ename = rs.getString("user");
cname = rs.getString("secret");
if(ename.equals(tf1.getText())&&cname.equals(tf2.getText()))
{
//JFrame.setDefaultLookAndFeelDecorated(true);
//DataWindow1 window = new DataWindow1();
lianliankan t=new lianliankan();
t.suiji();
t.go();
//window.validate();
}
}
Ex1Con.close(); //关闭数据库
}
}
} public class Dic
{
public static void main(String args[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
DataWindow window = new DataWindow();
window.validate();
// AddWin add = new AddWin(); } public void add()
{
}
}
import java.net.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
class DataWindow extends JFrame implements ActionListener
{
JFrame f;
JPanel p1,p2,p3;
FileDialog filedialog_save; //声明文件对话框
JTextField tf1,tf2;
JButton b1,b2,b3;
JLabel lb1,lb2;
DataWindow()
{
super("init");
this.setBounds(200,200,300,300);
this.setVisible(true);
tf1 = new JTextField(16);
tf1.setFont(new Font("",15,15));
tf2 = new JTextField(16);
tf2.setFont(new Font("",15,15));
b1 = new JButton("add");
b2 = new JButton("true");
b3 = new JButton("del");
JPanel p1 = new JPanel(),p2 = new JPanel(),p3 = new JPanel();//添加面板
lb1 = new JLabel("user:");
lb1.setFont(new Font("隶书",20,20));
lb2 = new JLabel("secret:");
lb2.setFont(new Font("隶书",20,20));
p1.setLayout(new GridLayout());
p1.add(lb1);
p1.add(tf1);
p1.add(lb2);
p1.add(tf2);
p2.setLayout(new FlowLayout());
p2.add("Left",b1);
p2.add("Center",b2);
p2.add("Right",b3);
this.setLayout(new BorderLayout());
this.add("North",p1);
this.add("South",p2);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
tf1.addActionListener(this);
tf2.addActionListener(this);
filedialog_save = new FileDialog(this,"保存文件对话框",FileDialog.SAVE);
filedialog_save.addWindowListener(new WindowAdapter() //对话框增加适配器
{
public void windowClosing(WindowEvent e)
{
filedialog_save.setVisible(false);
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0); }
});
}
public void actionPerformed(ActionEvent e) //实现按钮监听
{
if(e.getSource()==b2&&e.getSource()==tf1&&e.getSource()==tf2)
{
tf1.setText("");
tf2.setText("");
if(tf1.getText().equals("")||tf2.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"对象不能为空!","警告",
JOptionPane.WARNING_MESSAGE);
}
else{
try{ Listwords(); }
catch(SQLException ee){ }
}
}
else if(e.getSource()==b1)
{
Add add= new Add(); //AddWin是添加窗口的类
}
else if(e.getSource()==b3)
{
Del del = new Del(); //DelWin是删除窗口的类
}
}
public void Listwords() throws SQLException //实现查询功能
{
String cname,ename;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
//建立桥接器
Connection Ex1Con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=user\\user.mdb","","");
Statement Ex1Stmt = Ex1Con.createStatement();
if(lb1.getText().equals("user:")&&lb2.getText().equals("secret:"))
{
ResultSet rs = Ex1Stmt.executeQuery("SELECT * FROM 表1");
while( rs.next())
{
ename = rs.getString("user");
cname = rs.getString("secret");
if(ename.equals(tf1.getText())&&cname.equals(tf2.getText()))
{
//JFrame.setDefaultLookAndFeelDecorated(true);
//DataWindow1 window = new DataWindow1();
lianliankan t=new lianliankan();
t.suiji();
t.go();
//window.validate();
}
}
Ex1Con.close(); //关闭数据库
}
}
} public class Dic
{
public static void main(String args[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
DataWindow window = new DataWindow();
window.validate();
// AddWin add = new AddWin(); } public void add()
{
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货