用JAVA做一个登陆窗口要输入账号和密码密码输错3次就提示被锁定要有退出按钮

 我来答
窗子向南没风筝
推荐于2016-04-29 · 超过25用户采纳过TA的回答
知道答主
回答量:108
采纳率:63%
帮助的人:36.9万
展开全部

这个是用java se 做的  代码不复杂,就是 MyEclipse自动生成了一些页面布局的代码,对程序没什么影响,如果你不喜欢或者嫌复杂稍微改一下就可以了,因为大半夜了,布局我也不可能给你手写去,挺麻烦的。见谅。怎么还要用云盘呀 干脆再给你贴上来吧。就是布局那块 有点乱。

import javax.swing.JOptionPane;
public class Login extends javax.swing.JFrame {
 int flag = 3;
 private java.awt.Button button1;
 private java.awt.Button button2;
 private javax.swing.JPasswordField jPasswordField1;
 private java.awt.Label label1;
 private java.awt.Label label2;
 private java.awt.TextField textField1;

 /** Creates new form Login */
 public Login() {
  flag=3;
  initComponents();
  this.setVisible(true);
  button1.setEnabled(true);
 }

 //这个方法里的代码是 工具自动生成的窗体布局代码。直接用就可以,如果你不喜欢你就自己稍微修改一下就可以。直接运行一点问题没有。
 private void initComponents() {

  label1 = new java.awt.Label();
  textField1 = new java.awt.TextField();
  label2 = new java.awt.Label();
  jPasswordField1 = new javax.swing.JPasswordField();
  button1 = new java.awt.Button();
  button2 = new java.awt.Button();

  setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

  label1.setName("");
  label1.setText("\u7528\u6237\u540d\uff1a");

  textField1.setName("user");

  label2.setText("\u5bc6\u7801\uff1a");

  jPasswordField1.setName("password");

  button1.setLabel("\u767b\u5f55");
  button1.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    button1ActionPerformed(evt);
   }
  });

  button2.setLabel("\u9000\u51fa");
  button2.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    button2ActionPerformed(evt);
   }
  });

  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
    getContentPane());
  getContentPane().setLayout(layout);
  layout
    .setHorizontalGroup(layout
      .createParallelGroup(
        javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(
        layout
          .createSequentialGroup()
          .addGroup(
            layout
              .createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING,
                false)
              .addGroup(
                layout
                  .createSequentialGroup()
                  .addGap(
                    63,
                    63,
                    63)
                  .addGroup(
                    layout
                      .createParallelGroup(
                        javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(
                        label1,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(
                        label2,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(
                    40,
                    40,
                    40)
                  .addGroup(
                    layout
                      .createParallelGroup(
                        javax.swing.GroupLayout.Alignment.LEADING,
                        false)
                      .addComponent(
                        jPasswordField1)
                      .addComponent(
                        textField1,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        90,
                        Short.MAX_VALUE)))
              .addGroup(
                layout
                  .createSequentialGroup()
                  .addGap(
                    114,
                    114,
                    114)
                  .addComponent(
                    button1,
                    javax.swing.GroupLayout.PREFERRED_SIZE,
                    53,
                    javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(
                    29,
                    29,
                    29)
                  .addComponent(
                    button2,
                    javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE,
                    Short.MAX_VALUE)))
          .addContainerGap(155, Short.MAX_VALUE)));
  layout
    .setVerticalGroup(layout
      .createParallelGroup(
        javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(
        layout
          .createSequentialGroup()
          .addGap(82, 82, 82)
          .addGroup(
            layout
              .createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(
                textField1,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(
                label1,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGap(26, 26, 26)
          .addGroup(
            layout
              .createParallelGroup(
                javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(
                label2,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(
                jPasswordField1,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGap(38, 38, 38)
          .addGroup(
            layout
              .createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(
                button1,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(
                button2,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE))
          .addContainerGap(84, Short.MAX_VALUE)));

  button1.getAccessibleContext().setAccessibleName("");

  pack();
 }// </editor-fold>
 

 private void button2ActionPerformed(java.awt.event.ActionEvent evt) {
  System.exit(0);
 }

 @SuppressWarnings("deprecation")
 private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
  String user = textField1.getText();
  String pass = jPasswordField1.getText();
  System.out.println(user);
  System.out.println(pass);
  if ("admin".equals(user) && pass.equals(pass)) {
   JOptionPane.showMessageDialog(null, "登录成功");
   this.setVisible(false);
  } else {
  
   flag--;
   JOptionPane.showMessageDialog(null, "登录失败,还有"+flag+"次机会");
   
  }
  if (flag <= 0) {
   button1.setEnabled(false);
  }
 }

 public static void main(String args[]) {
  java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
    new Login().setVisible(true);
   }
  });
 }

}

年俊梅e7
2013-06-03 · TA获得超过227个赞
知道小有建树答主
回答量:381
采纳率:0%
帮助的人:288万
展开全部
什么样的 说清楚是java web 还是 swing 还是什么
追问
swing
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式