标题:麻烦大神指点下java代码
只看楼主
暂不存在
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2013-5-30
结帖率:75%
已结贴  问题点数:20 回复次数:3 
麻烦大神指点下java代码
以作备注在问题区域,请看。

package test;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ex127 {
    public Ex127(){
        new LoginWindow();
    }
    public static void main(String[] args){
        new Ex127();
    }
}
class LoginWindow extends JFrame implements ActionListener
{
    JLabel bq1=new JLabel("请输入用户名");
    JLabel bq2=new JLabel("请输入密码");
    JTextField wbk=new JTextField(10);
    JPasswordField mmk=new JPasswordField(10);
    JButton an1=new JButton("登录");
    JButton an2=new JButton("重置");
    JButton an3=new JButton("注册");

    public LoginWindow(){
        this.setLayout(null);
        this.add(bq1);
        this.add(bq2);
        this.add(wbk);
        this.add(mmk);
        this.add(an1);
        an1.addActionListener(this);
        an1.setActionCommand("denglu");
        this.add(an2);
        an2.addActionListener(this);
        an2.setActionCommand("chongzhi");
        this.add(an3);
        bq1.setBounds(20,10,80,20);
        bq2.setBounds(20,50,100,20);
        wbk.setBounds(100,10,100,20);
        mmk.setBounds(100,50,100,20);
        an1.setBounds(20,100,60,25);
        an2.setBounds(100,100,60,25);
        an3.setBounds(180,100,60,25);
        this.setSize(380,250);
        //不允许用户改变窗口的大小
        this.setResizable(false);
        //让窗口在屏幕的正中间显示
        this.setVisible(true);
        this.setSize(300,200);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("denglu"))
        {
            if(wbk.getText()==null){                                    //这里没有输入用户名,点登陆按钮为什么不弹出提示"请输入用户名!",下面也是?
                JOptionPane.showMessageDialog(null,"请输入用户名!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
            else if(mmk.getText()==null)
            {
                JOptionPane.showMessageDialog(null,"请输入密码!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
            else
            {
                //this.dispose();
                JOptionPane.showMessageDialog(null, wbk.getText()+" 已成功登陆!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if(e.getActionCommand().equals("chongzhi"))
        {
            wbk.setText(null);
            mmk.setText(null);

        }
    }

}

[ 本帖最后由 暂不存在 于 2013-12-3 18:45 编辑 ]
搜索更多相关主题的帖子: import 用户名 public 输入密码 package 
2013-12-03 18:42
新一x
Rank: 2
等 级:论坛游民
帖 子:6
专家分:20
注 册:2012-3-27
得分:15 
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ex127 {
    public Ex127(){
        new LoginWindow();
    }
    public static void main(String[] args){
        new Ex127();
    }
}
class LoginWindow extends JFrame implements ActionListener
{
    JLabel bq1=new JLabel("请输入用户名");
    JLabel bq2=new JLabel("请输入密码");
    JTextField wbk=new JTextField(10);
    JPasswordField mmk=new JPasswordField(10);
    JButton an1=new JButton("登录");
    JButton an2=new JButton("重置");
    JButton an3=new JButton("注册");

    public LoginWindow(){
        this.setLayout(null);
        this.add(bq1);
        this.add(bq2);
        this.add(wbk);
        this.add(mmk);
        this.add(an1);
        an1.addActionListener(this);
        an1.setActionCommand("denglu");
        this.add(an2);
        an2.addActionListener(this);
        an2.setActionCommand("chongzhi");
        this.add(an3);
        bq1.setBounds(20,10,80,20);
        bq2.setBounds(20,50,100,20);
        wbk.setBounds(100,10,100,20);
        mmk.setBounds(100,50,100,20);
        an1.setBounds(20,100,60,25);
        an2.setBounds(100,100,60,25);
        an3.setBounds(180,100,60,25);
        this.setSize(380,250);
        //不允许用户改变窗口的大小
        this.setResizable(false);
        //让窗口在屏幕的正中间显示
        this.setVisible(true);
        this.setSize(300,200);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        String s=null;
    }
    @SuppressWarnings("deprecation")
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("denglu"))
        {   
            if(wbk.getText().equals("")){
               
                JOptionPane.showMessageDialog(null,"请输入用户名!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
            else if(mmk.getText().equals(""))
            {
                JOptionPane.showMessageDialog(null,"请输入密码!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
            else
            {
                //this.dispose();
                JOptionPane.showMessageDialog(null, wbk.getText()+" 已成功登陆!", "提示", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if(e.getActionCommand().equals("chongzhi"))
        {
            wbk.setText(null);
            mmk.setText(null);

        }
    }

}
2013-12-04 15:52
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
得分:5 
字符串比较需要用到 equals 函数哦

三十年河东,三十年河西,莫欺少年穷!
2013-12-04 16:12
暂不存在
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2013-5-30
得分:0 
对了,怎么怎么粗心
2013-12-04 22:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424653-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017984 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved