通过继承JFrame写一个类,该类中有一个隐藏当前FRAME的按钮,请问该如何编写该按钮的代码?具体代码如下:class RegFrame extends JFrame
{
public RegFrame()
{
setTitle("用户注册");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
setLocation(screenSize.width/4,screenSize.height/4);
Container contentPane=getContentPane();
okButton=new JButton("注册");
calButton=new JButton("取消");
JPanel buttonPanel=new JPanel();
buttonPanel.add(okButton);
buttonPanel.add(calButton);
contentPane.add(buttonPanel,BorderLayout.SOUTH);
ActionListener okAction=new RegFrame.okAction();
ActionListener calAction=new RegFrame.calAction();
calButton.addActionListener(calAction);
okButton.addActionListener(okAction);
inputPanel=new JPanel();
inputPanel.setLayout(new GridLayout(0,2));
contentPane.add(inputPanel,BorderLayout.CENTER);
usernameText=new JTextField();
passwordText=new JPasswordField();
usersexText=new JTextField();
JLabel userLabel=new JLabel("用户名:");
JLabel passLabel=new JLabel("密 码:");
JLabel sexLabel=new JLabel("性 别:");
inputPanel.add(userLabel);
inputPanel.add(usernameText);
inputPanel.add(passLabel);
inputPanel.add(passwordText);
inputPanel.add(sexLabel);
inputPanel.add(usersexText);
}
private class okAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url ="jdbc:microsoft:sqlserver://192.168.0.86;DatabaseName=mmc";
//Test为你的数据库的
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String username=usernameText.getText();
String spassword=new String(passwordText.getPassword());
String ssex=usersexText.getText();
String sql = "Insert mmc(username,userpwd,usersex) values('"+username+"','"+spassword+"','"+ssex+"')";
stmt.execute(sql);
stmt.close();
conn.close();
//JOptionPane.showMessageDialog(null,"注册成功!",JOptionPane.INFORMATION_MESSAGE,null);
JOptionPane.showMessageDialog(null,"注册成功!","用户注册",JOptionPane.INFORMATION_MESSAGE); }
catch (Exception ee) {
System.out.println(ee);
JOptionPane.showMessageDialog(null,"出错了!","用户注册",JOptionPane.INFORMATION_MESSAGE);
}
}
}
private class calAction implements ActionListener
{
public void actionPerformed(ActionEvent e2)
{
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
}
}
public static final int DEFAULT_WIDTH=200;
public static final int DEFAULT_HEIGHT=170;
private JButton okButton;
private JButton calButton;
private JPanel inputPanel;
private JTextField usernameText;
private JTextField usernameText2;
private JPasswordField passwordText;
private JTextField usersexText;
}
{
public RegFrame()
{
setTitle("用户注册");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
setLocation(screenSize.width/4,screenSize.height/4);
Container contentPane=getContentPane();
okButton=new JButton("注册");
calButton=new JButton("取消");
JPanel buttonPanel=new JPanel();
buttonPanel.add(okButton);
buttonPanel.add(calButton);
contentPane.add(buttonPanel,BorderLayout.SOUTH);
ActionListener okAction=new RegFrame.okAction();
ActionListener calAction=new RegFrame.calAction();
calButton.addActionListener(calAction);
okButton.addActionListener(okAction);
inputPanel=new JPanel();
inputPanel.setLayout(new GridLayout(0,2));
contentPane.add(inputPanel,BorderLayout.CENTER);
usernameText=new JTextField();
passwordText=new JPasswordField();
usersexText=new JTextField();
JLabel userLabel=new JLabel("用户名:");
JLabel passLabel=new JLabel("密 码:");
JLabel sexLabel=new JLabel("性 别:");
inputPanel.add(userLabel);
inputPanel.add(usernameText);
inputPanel.add(passLabel);
inputPanel.add(passwordText);
inputPanel.add(sexLabel);
inputPanel.add(usersexText);
}
private class okAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url ="jdbc:microsoft:sqlserver://192.168.0.86;DatabaseName=mmc";
//Test为你的数据库的
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String username=usernameText.getText();
String spassword=new String(passwordText.getPassword());
String ssex=usersexText.getText();
String sql = "Insert mmc(username,userpwd,usersex) values('"+username+"','"+spassword+"','"+ssex+"')";
stmt.execute(sql);
stmt.close();
conn.close();
//JOptionPane.showMessageDialog(null,"注册成功!",JOptionPane.INFORMATION_MESSAGE,null);
JOptionPane.showMessageDialog(null,"注册成功!","用户注册",JOptionPane.INFORMATION_MESSAGE); }
catch (Exception ee) {
System.out.println(ee);
JOptionPane.showMessageDialog(null,"出错了!","用户注册",JOptionPane.INFORMATION_MESSAGE);
}
}
}
private class calAction implements ActionListener
{
public void actionPerformed(ActionEvent e2)
{
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
//这里写代码隐藏该FRAME,如何写?
}
}
public static final int DEFAULT_WIDTH=200;
public static final int DEFAULT_HEIGHT=170;
private JButton okButton;
private JButton calButton;
private JPanel inputPanel;
private JTextField usernameText;
private JTextField usernameText2;
private JPasswordField passwordText;
private JTextField usersexText;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货