بدايتي لإنشاء برنامج كانت شاشة دخول برقم سري, ولكن توقفت في اول خطوه ولا اعلم مالخطأ في هذا الكود:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Login
{
public static void main(String[] args)
{
public static String userId = "usrid";
String password = "pass";
{
JFrame frame = new JFrame("Login");
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(9);
pass.setEchoChar('*');
pass.addActionListener(new AL());
panel.add(label, BorderLayout.WEST);
panel.add(pass, BorderLayout.WEST);
}
static class AL implements ActionListener
{
public actionPerformed (ActionEvent e)
{
JPasswordField input = (JPasswordField) e.getSource();
char[] passy = input.getPassword();
String p = String("passy);
if (p.equals(password))
{
JOptionPane.showMessageDialog(null,"Correct");
else
JOptionPane.showMessageDialog(null,"Incorrect");
}
}
}
}
}مع الشكر الجزيل،
BYQ