为什么面板显示不出?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(250,250,600,400);
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("regist");
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);
f.setLayout(new BorderLayout());
f.add("North",p1);
f.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)
{
tf1.setText("");
if(tf1.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()))
{
DicWin dw = new DicWin();
}
}
Ex1Con.close(); //关闭数据库
if(tf1.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"查无此user!","警告",
JOptionPane.WARNING_MESSAGE);
}
}
}
}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(250,250,600,400);
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("regist");
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);
f.setLayout(new BorderLayout());
f.add("North",p1);
f.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)
{
tf1.setText("");
if(tf1.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()))
{
DicWin dw = new DicWin();
}
}
Ex1Con.close(); //关闭数据库
if(tf1.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"查无此user!","警告",
JOptionPane.WARNING_MESSAGE);
}
}
}
}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()
{
}
}
解决方案 »
- java编写的计算器中,算出的诡异结果,求正解!
- 统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数?
- JAVA问题
- 集合相减操作为什么总是抛出异常java.lang.UnsupportedOperationException
- 传递参数中的疑问
- 初学者:程序能正确执行,可是编译时提示错误,这是什么错误?
- 请问java如何能够获取cpu使用率?
- 在线等。。。请帮我好吗?
- Java中static申明后的变量有什么用?
- 安装jrun后是否还需要配置IIS 或APACHE
- 一道关于java -classpath参数的问题
- 看了好多帖子说J2SE学完后学J2EE,想知道大家说的J2EE具体是什么?
f.add("North",p1);
f.add("South",p2);
換成這個this.setVisible(true); this.setLayout(new BorderLayout());
this.add("North", p1);
this.add("South",p2);
是不是這樣?