这个Java程序错在哪里,怎么解决并输出正确的结果啊

这个Java程序错在哪里,怎么解决并输出正确的结果啊,第1张

你定义的tf1和tf2是为了获取用户名和密码的吧。那你试下我改的对不对:

public class dengLu {

MyPolice police= new MyPolice();

static JTextField tf1=new JTextField(10);

//static JTextField tf1=new JTextField(18);--获取密码不应该用JTextField吧

static JPasswordField tf2=new JPasswordField(18);

public dengLu(){

JFrame frame = new JFrame();

framesetSize(400,200);

framesetTitle("登陆窗口");

framesetBackground(new Color(0,125,13));

framesetLayout(new FlowLayout(FlowLayoutLEFT));

JLabel label1 = new JLabel("用户名:");

frameadd(label1);

//JTextField tf1 = new JTextField(10);

frameadd(tf1);

JLabel label2 = new JLabel("密码:");

frameadd(label2);

//JPasswordField pf1 = new JPasswordField(10);

frameadd(tf2);

JButton button1 = new JButton("确定");

JButton button2 = new JButton("退出");

frameadd(button1);

frameadd(button2);

button1addActionListener(police);

button2addActionListener(police);

framesetVisible(true);

}

}

class MyPolice implements ActionListener {

public void actionPerformed(ActionEvent e) {

String str=egetActionCommand();

if(strequals("退出")){

Systemexit(0);

}

else{

String oper1 = tf1gettext();

String oper2 = tf2gettext();

//double b = DoubleparseDouble (oper1);--不需要把获取的用户名强制转换成Double

//double c = DoubleparseDouble("admin");

//int a = IntegerparseInt(oper2);

double password = DoubleparseDouble (oper2);

if(oper1equals("admin")&& passwordequals(111)){

JOptionPaneshowMessageDialog(null,"登陆成功");

}

else{

JOptionPaneshowMessageDialog(null,"登陆失败!请输入正确的用户名和密码!");

}

}

}

}

这个和你想要的差不多了

import javaawtFlowLayout;

import javaawtTextField;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJTextField;

public class Test extends JFrame implements ActionListener {// 继承窗体JFrame,声明借口ActionListener。

/

/

private static final long serialVersionUID = 1L;

JLabel input = new JLabel(" 请输入密码:");// 实例化一个标签对象。

TextField password = new TextField(13);// 实例化一个文本框对象。

JButton submit = new JButton("提交");// 实例化一个按钮对象。

JButton reset = new JButton("重置");

JLabel output = new JLabel("你输入的密码是:");

JTextField show = new JTextField(10);

Test() {// 构造函数

super("00");// 窗体名字。

thissetLayout(new FlowLayout());// 窗体布局。(流式布局)

submitaddActionListener(this);// 给按钮添加事件监听。(给按钮注册监听器)

resetaddActionListener(this);

thisadd(input);// 将各组件添加在窗体上。

passwordsetEchoChar('');// 设置掩码。

thisadd(password);

thisadd(output);

thisadd(show);

thisadd(submit);

thisadd(reset);

thissetSize(245, 200);// 设置窗体大小。

thissetVisible(true);// 设置窗体可见。

thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);// 设置窗体可关闭,程序可正常退出。

}

public static void main(String[] args) {

new Test();// 实例化类

}

public void actionPerformed(ActionEvent e) {

String str = passwordgetText();// 将password文本框中的字符取出存在str中。

JButton jb = (JButton) egetSource();// 获得按钮事件的事件源

if (jb == submit) {// 点击了submit按钮

showsetText(str);// 设置show文本框中的内容为str中的内容

}

if (jb == reset) {// 点击了reset按钮

passwordsetText(null);// 文本框清空

showsetText(null);

}

}

}

把str!="123"改为!strequals("123")

str=="123"改为strequals("123")

就可以了,java里面对字符串的比较用Stringequals(str)

要获得原始密码,那还加密做什么~~

private JPasswordField password = new JPasswordField(30);

String password = StringvalueOf(thispasswordgetPassword());

这样获取不到吗~~

以上就是关于这个Java程序错在哪里,怎么解决并输出正确的结果啊全部的内容,包括:这个Java程序错在哪里,怎么解决并输出正确的结果啊、JAVA .编写GUI程序,要求:用户在密码框中输入数据,将输入的字符显示在另一个文本框中。、Java的GUI编程,密码框内容获取不正确等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9340191.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存