所以我正在做一个项目,我试图从程序中禁用框架和字段,以便只有窗口在前面,这个是活动的,这是我的代码:
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。