gpt4 book ai didi

java - 我将如何禁用文本框?

转载 作者:行者123 更新时间:2023-11-29 03:43:18 24 4
gpt4 key购买 nike

所以我正在做一个项目,我试图从程序中禁用框架和字段,这样只有窗口在前面才是 Activity 的这是我的代码:

 import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class password
{
private static String password = "pass";
public static void main(String[]args) {
JFrame frame = new JFrame("Password");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,100);
JLabel label = new JLabel("Enter password");
JPanel panel = new JPanel();
frame.add(panel);
JPasswordField pass = new JPasswordField(10);
pass.setEchoChar('*');
pass.addActionListener(new AL());
panel.add(label, BorderLayout.WEST);
panel.add(pass, BorderLayout.WEST);
}
static class AL implements ActionListener
{
public void actionPerformed(ActionEvent e) {
JPasswordField input = (JPasswordField) e.getSource();
char [] passy = input.getPassword();
String p = new String(passy);
if (p.equals(password)){
JOptionPane.showMessageDialog(null, "Correct");
System.out.print("Welcome to Adam's Quirky program.");



}
else
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
}

我目前使用的程序是Eclipse。

最佳答案

我会看一下模态对话框。

要么使用 JOptionPane 要么自己动手。

如果这些不符合您的需求,请尝试查看 JLayer (Java 7) 或 JXLayer (Java 6 及以下版本)

看看LockableUI (有点过时了,但基本思路是一样的)

如果那没有吸引力,您可以使用“阻挡玻璃板”

看看

举个例子

关于java - 我将如何禁用文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12169662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com