CS结构系统的退出如下: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 "系统提示:", 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结构的退出直接用windows.close()方法就行了!
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、虚拟空间、营销软件、网站建设、宿豫网站维护、网站推广。
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创建一个JFC工程,会出现两个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);
}
}
网站名称:java窗口登陆代码 java登录界面代码简单
转载源于:https://www.cdcxhl.com/article18/doeoogp.html
成都网站建设公司_创新互联,为您提供电子商务、移动网站建设、品牌网站制作、企业网站制作、服务器托管、网站营销
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联