| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 349 人关注过本帖
标题:求大神帮忙能点清空按钮就让用户名和密码框中的数据清空
只看楼主 加入收藏
ws1075020131
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-12-26
结帖率:0
  已结贴   问题点数:20  回复次数:1   
求大神帮忙能点清空按钮就让用户名和密码框中的数据清空

package 登录;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class  登录{
public static void main(String[] args) {
        登录 frame=new 登录();
        frame.show();
}
        public void show() {
        JFrame frame=new JFrame();
        frame.setTitle("登陆界面");
        frame.setDefaultCloseOperation(3);
        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);
        frame.setLayout(new FlowLayout());
        JLabel L1=new JLabel("账号:");
        JTextField te1=new JTextField(12);
        JLabel L2=new JLabel("密码:");
        JPasswordField te2=new JPasswordField(12);
           te2.setEchoChar('*');
        JLabel L=new JLabel();
         frame.add(L);
         frame.add(L1);
         frame.add(te1);
         frame.add(L2);
         frame.add(te2);
        JCheckBox checkbox1=new JCheckBox("老师");
        frame.add(checkbox1);
        JCheckBox checkbox2=new JCheckBox("学生");
        frame.add(checkbox2);
         JButton B1=new JButton("登陆");

        ButtonListener li1=new ButtonListener(te1,te2);

        B1.addActionListener(li1);

        frame.add(B1);

        JButton B2=new JButton("清空");

        frame.add(B2);

        frame.setVisible(true);
        JTextField jt=new JTextField("B2");
                jt.addMouseListener(new java.awt.event.MouseAdapter() {
                    public void mouseClicked(java.awt.event.MouseEvent e) {
                        jt.setText("B2");
                    }
                });
               
        

    }
public class ButtonListener implements java.awt.event.ActionListener{

            public JTextField te1=new JTextField();

            public JPasswordField te2=new JPasswordField();
            public ButtonListener(JTextField te1,JPasswordField te2) {

                this.te1=te1;   
                this.te2=te2;

            }

            public void actionPerformed(ActionEvent e) {

                String zhang=te1.getText();

                String mi= String.valueOf(te2.getPassword());

                if((zhang.equals("123456")==true)&&(mi.equals("111")==true)) {
             }
                else JOptionPane.showMessageDialog(null, "密码错误", null, 0);
               
            }

            

        }

}
2018-12-26 08:09
幻紫灵心
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:山咔咔里面
等 级:贵宾
威 望:34
帖 子:322
专家分:2218
注 册:2018-3-30
  得分:20 
(输入框名).setText("");

saber,别哭.
2018-12-26 19:27







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

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