Code: Select all
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
public class LoginGateway extends JPanel
implements ActionListener {
private static String OK = "ok";
private static String HELP = "help";
private JFrame controllingFrame;
private JPasswordField passwordField;
public LoginGateway(JFrame f) {
controllingFrame = f;
passwordField = new JPasswordField(10);
passwordField.setActionCommand(OK);
passwordField.addActionListener(this);
JLabel label = new JLabel("Enter Your Password For Pablo's Private Sector Gateway: ");
label.setLabelFor(passwordField);
JComponent buttonPane = createButtonPanel();
JPanel textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
textPane.add(label);
textPane.add(passwordField);
add(textPane);
add(buttonPane);
}
protected JComponent createButtonPanel() {
JPanel p = new JPanel(new GridLayout(0,1));
JButton okButton = new JButton("OK");
JButton helpButton = new JButton("Help");
okButton.setActionCommand(OK);
helpButton.setActionCommand(HELP);
okButton.addActionListener(this);
helpButton.addActionListener(this);
p.add(okButton);
p.add(helpButton);
return p;
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (OK.equals(cmd)) {
char[] input = passwordField.getPassword();
if (isPasswordCorrect(input)) {
JOptionPane.showMessageDialog(controllingFrame,
"Success! Welcome Pablo");
javax.swing.JFrame topFrame = new JFrame();
javax.swing.JPanel topPanel = new JPanel();
javax.swing.JSplitPane splitPane = new JSplitPane();
javax.swing.JPanel leftPanel = new JPanel();
javax.swing.JPanel rightPanel = new JPanel();
javax.swing.JScrollPane leftScrollPane = new JScrollPane();
javax.swing.JScrollPane rightScrollPane = new JScrollPane();
javax.swing.JTree leftTree = new JTree();
//layouts
// with border layout, components take maximum size they could get.
topFrame.setLayout(new BorderLayout());
topPanel.setLayout(new BorderLayout());
leftPanel.setLayout(new BorderLayout());
rightPanel.setLayout(new BorderLayout());
topPanel.add(splitPane);
splitPane.setRightComponent(rightPanel);
splitPane.setLeftComponent(leftPanel);
splitPane.setDividerLocation(200);
rightPanel.add(rightScrollPane);
leftPanel.add(leftScrollPane);
leftScrollPane.getViewport().add(leftTree);
topFrame.setSize(600, 500);
topFrame.setContentPane(topPanel);
topFrame.setVisible(true);
tree.setEditable(true);
} else {
JOptionPane.showMessageDialog(controllingFrame,
"Sorrrrry, YOU DUMB AS HELL",
"Error Message For Dumbasses",
JOptionPane.ERROR_MESSAGE);
}
Arrays.fill(input, '0');
passwordField.selectAll();
resetFocus();
} else {
JOptionPane.showMessageDialog(controllingFrame,
"You have failed.");
}
}
private static boolean isPasswordCorrect(char[] input) {
boolean isCorrect = true;
char[] correctPassword = { '1', '0', '0', '8', 'p', 'a', 'b', 's' };
if (input.length != correctPassword.length) {
isCorrect = false;
} else {
isCorrect = Arrays.equals (input, correctPassword);
}
Arrays.fill(correctPassword,'0');
return isCorrect;
}
protected void resetFocus() {
passwordField.requestFocusInWindow();
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Pablo's Secure Sector Gateway");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final PasswordDemo newContentPane = new PasswordDemo(frame);
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
newContentPane.resetFocus();
}
});
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}
LoginGateway.java:91: error: cannot find symbol
tree.setEditable(true);
^
symbol: variable tree
location: class LoginGateway
./PasswordDemo.java:91: error: cannot find symbol
tree.setEditable(true);
^
symbol: variable tree
location: class PasswordDemo
2 errors
I don't know why it says that if its not even IN my code, I put it in for one try but then I took it out. It is an error when compiling.
I would like to have the code right and make the JTree editable.
Thanks a lot!!