CS結(jié)構系統(tǒng)的退出如下:public void init() {\x0d\x0a this.setTitle("用戶登錄界面");\x0d\x0a this.add(createCenterPane());\x0d\x0a this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0a this.setSize(new Dimension(450, 335));\x0d\x0a this.setLocationRelativeTo(null);\x0d\x0a // this.setVisible(true);\x0d\x0a this.addWindowListener(new WindowAdapter() {\x0d\x0a public void windowClosing(WindowEvent e) {\x0d\x0a int choose = JOptionPane.showConfirmDialog(null, "是否要退出登錄界面?",\x0d\x0a "系統(tǒng)提示:", JOptionPane.YES_NO_OPTION);\x0d\x0a if (choose == JOptionPane.YES_OPTION) {\x0d\x0a System.exit(1);\x0d\x0a }\x0d\x0a }\x0d\x0a });\x0d\x0a }其中this為JFrame對象。BS結(jié)構的退出直接用windows.close()方法就行了!
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名申請、虛擬空間、營銷軟件、網(wǎng)站建設、宿豫網(wǎng)站維護、網(wǎng)站推廣。
import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用戶名"); \x0d\x0aJLabel lbl2=new JLabel("密碼"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("確定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陸"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陸成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用戶名或密碼錯誤!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}
用JCreator創(chuàng)建一個JFC工程,會出現(xiàn)兩個java文件,只改其中一個就行了.....-------------------------/**
* @(#)TestFrame.java
*
* JFC Test application
*
* @author
* @version 1.00 2010/5/30
*/import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestFrame extends JFrame {
/**
* The constructor
*/
public TestFrame() {
JLabel lblUserName = new JLabel("用戶名");
final JTextField txtUserName = new JTextField(); // 用戶名
JLabel lblPassword = new JLabel("密碼");
final JPasswordField pwfPassword = new JPasswordField(); // 密碼
JButton btnLogin = new JButton("確定");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!txtUserName.getText().equals("111") || !pwfPassword.getText().equals("111")) {
JOptionPane.showMessageDialog(null, "用戶名或密碼錯誤", "錯誤", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "成功登陸", "正確", JOptionPane.INFORMATION_MESSAGE);
}
}
});
JButton btnCancel = new JButton("取消");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TestFrame.this.windowClosed();
}
}); // Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TestFrame.this.windowClosed();
}
}
);
GroupLayout layout = new GroupLayout(this.getContentPane());
this.getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true); GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
hGroup.addGroup(layout.createParallelGroup().addComponent(lblUserName).addComponent(lblPassword));
hGroup.addGroup(layout.createParallelGroup().addComponent(txtUserName, GroupLayout.PREFERRED_SIZE, 170,
GroupLayout.PREFERRED_SIZE).addComponent(pwfPassword, GroupLayout.PREFERRED_SIZE, 170,
GroupLayout.PREFERRED_SIZE).addGroup(GroupLayout.Alignment.CENTER,
layout.createSequentialGroup().addComponent(btnLogin).addComponent(btnCancel)));
layout.setHorizontalGroup(hGroup); GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
vGroup.addGap(15);
vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(lblUserName)
.addComponent(txtUserName, GroupLayout.PREFERRED_SIZE, 25,
GroupLayout.PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(lblPassword)
.addComponent(pwfPassword, GroupLayout.PREFERRED_SIZE, 25,
GroupLayout.PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(btnLogin).addComponent(
btnCancel));
layout.setVerticalGroup(vGroup);
setTitle("登陸");
setSize(new Dimension(250, 150));
setLocationRelativeTo(null);
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
}