How PACKAGE argument for .External/.External2 works?

Java programming problem?

  • Well I'm trying to make a simple login GUI and everything works perfectly up until i try and login, it doesn't seem to think i registered even though i type in EXACTLY what i registered with. I will post the code and you can see my logic, i will post the two classes that it uses, the registerscreen and loginscreen: package net.sf; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LoginScreen extends JFrame{ private boolean validcreds = false; private JTextField user; private JPasswordField pass; private String username = null; private String password = null; private JButton logbutton; private JLabel lab1; private JLabel lab2; private Handler h = new Handler(); public LoginScreen(){ super("Login Screen"); setLayout(new FlowLayout()); user = new JTextField(20); pass = new JPasswordField(20); lab1 = new JLabel("Username:"); lab2 = new JLabel("Password:"); logbutton = new JButton("Login"); add(lab1); add(user); add(lab2); add(pass); add(logbutton); logbutton.addMouseListener(h); setDefaultCloseOperation(JFrame.EXIT… setSize(640,480); setVisible(true); } public void setVisibility(boolean visible){ setVisible(visible); } private class Handler extends MouseAdapter{ public void mouseClicked(MouseEvent event){ if (event.getSource() == logbutton){ username = user.getText(); password = pass.getText(); if (username != null&&password != null){ for(int i = 0;i<RegScreen.usernames.length;i++){ if(username == RegScreen.usernames[i] && password == RegScreen.passwords[i]){ validcreds = true; } } if (validcreds == true){ JOptionPane.showMessageDialog(nu… logged in!"); setVisibility(false); new MenuScreen(); } else{ JOptionPane.showMessageDialog(nu… make sure you're registered!"); setVisibility(false); new MenuScreen(); } } else JOptionPane.showMessageDialog(nul… something in the boxes"); } } } } package net.sf; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class RegScreen extends JFrame{ public static String[] usernames = new String[20]; public static String[] passwords = new String[20]; private int count = 0; private JTextField username; private JPasswordField password; private JButton regbutton; private JLabel lab1; private JLabel lab2; public RegScreen(){ super("Register Screen"); setLayout(new FlowLayout()); username = new JTextField(20); password = new JPasswordField(20); lab1 = new JLabel("Username:"); lab2 = new JLabel("Password:"); regbutton = new JButton("Register"); add(lab1); add(username); add(lab2); add(password); add(regbutton); regbutton.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent event){ if (username.getText() != null&&password.getText() != null){ if (count == 0){ usernames[count] = username.getText(); passwords[count] = password.getText(); count++; JOptionPane.showMessageDialog(nu… registered!"); setVisibility(false); new MenuScreen(); } else{ usernames[count] = username.getText(); passwords[count] = username.getText(); count++; JOptionPane.showMessageDialog(nu… registered!"); setVisibility(false); new MenuScreen(); } } else{ JOptionPane.showMessageDialog(nul… leave the boxes blank"); } } }); setDefaultCloseOperation(JFrame.EXIT… setSize(640,480); setVisible(true); } public void setVisibility(boolean visible){ setVisible(visible); } } P.S. For some reason yahoo turns the string arguments in the showMessageDialog method into nu... and then half the actual string argument, so thats not the problem.

  • Answer:

    Looks like the issue is when you compare the strings. string1.equals(string2); string1 == string2 doesn't check if the strings are the same value, it checks if they have the same address or if they are the same instance of the String class, I forget which, but definitely not the value of the variables.

TheJavaC... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.