class UserFrame extends JFrame
{
public UserFrame()
{
setTitle("用户管理");
UserPanel panel=new UserPanel();
add(panel);
}
}//定义JPanel类
class UserPanel extends JPanel
{
JTextField jtext1;
JButton btm1;
//分别定义链接,结果集,执行;
Connection conn;
ResultSet resultSet;
Statement state;
String str="jdbc:mysql://localhost:3306/test";
public UserPanel()
{
btm1=new JButton("显示用户");
jtext1=new JTextField();
add(jtext1);
                add(btm1);
btm1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
public void connDB()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null, "数据库错误");
}
try
{
conn=DriverManager.getConnection(str,"root","test");
state=conn.createStatement();
}catch(SQLException e)
{
JOptionPane.showMessageDialog(null, "数据库连接失败");

}
}
public void closeDB()
{
try
{
state.close();
conn.close();
}catch (SQLException e)
{
JOptionPane.showMessageDialog(null,"数据库关闭失败");
}
}
}
public class User {
public static void main(String[] args) {
// TODO 自动生成方法存根
UserFrame frame=new UserFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation( (screenSize.width - frameSize.width) / 2,
                      (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
                pack(true);
}}