Ich schreibe ein Programm für die Schule und möchte überprüfen, ob das eingegebene Passwort korrekt ist, aber das Programm läuft weiter, selbst wenn das Passwort falsch ist. Unten ist mein gesamtes Programm!Programm überprüfen, ob das Passwort korrekt ist
public class ma_RocketProgram
{
static Console c;
//***********************************Main Program******************************
public static void main (String[] args)
{
c = new Console (35, 85);
c.setColor (Color.black);
c.fillRect (0, 0, 700, 550);
Image picture1 = loadImage ("USA.png");
c.drawImage (picture1, 200, 100, null);
IntroMessage();
c.getChar();
Password();
c.setColor (Color.blue);
c.drawRect (175, 475, 300, 10);
for (int a = 176; a <= 465; a++)
{
c.setColor (Color.green);
c.fillRect(a, 476, 10, 9);
try
{
Thread.sleep(25);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
}
//********************************Image Loader Method**************************
public static Image loadImage (String name)
{
Image img = null;
try
{
img = ImageIO.read (new File (name));
}
catch (IOException e)
{
}
return img;
}
//******************************Intro Message*************************************
public static void IntroMessage()
{
Font f = new Font ("Courier New", Font.PLAIN, 30);
c.setColor (Color.green);
c.setFont (f);
c.drawString ("W", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" e", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" l", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" c", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" o", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" m", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" e", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" t", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" o", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" t", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" h", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" e", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" R", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" o", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" c", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" k", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" e", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" t", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" L", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" a", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" u", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" n", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" c", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" h", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" e", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" r", 60, 25);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString ("P", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" r", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" o", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" g", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" r", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" a", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.drawString (" m", 250, 60);
try
{
Thread.sleep(50);
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
c.setColor(Color.white);
c.drawRect(215, 360, 215, 55);
Font f2 = new Font ("Courier New", Font.PLAIN, 15);
c.setColor (Color.green);
c.setFont (f2);
c.drawString ("Press any key to", 245, 375);
c.drawString ("display password field", 225, 400);
}
//************************************Password*************************
public static void Password()
{
JPanel panel = new JPanel();
JLabel label = new JLabel ("Enter the password");
JPasswordField pass = new JPasswordField(10);
panel.add (label);
panel.add (pass);
String[] options = new String[]{"Enter", "Cancel"};
int option = JOptionPane.showOptionDialog (null, panel, "Rocket Launcher", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
if (option == 0)
{
char[] password = pass.getPassword();
char[] passw = new char[]{'1'};
boolean b = Arrays.equals(password, passw);
if (b = false)
{
System.exit(0);
}
}
}
}
Vielleicht 'Arrays.equals versuchen (Passwort, passw)' – MadProgrammer
Mögliches Duplikat [Vergleich Arrays in Java] (http://stackoverflow.com/questions/5588460/comparing-arrays- in-java) – MadProgrammer
Ich habe diese Methode versucht, aber kein Glück. Ich habe die Passwort-Methode in einem separaten größeren Programm und wenn das Passwort falsch ist, wird es nicht verlassen. –