John
Posts: 13
Nickname: icej
Registered: Sep, 2003
|
|
Re: How can i hide an applet?
|
Posted: Oct 5, 2003 11:02 AM
|
|
Here is the whole applet:
package wages;
/** * Insert the type's description here. * Creation date: (10/4/2003 6:50:44 PM) * @author: */ import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*;
/** * Insert the type's description here. * Creation date: (10/2/2003 8:02:27 PM) * @author: */ public class Login extends javax.swing.JFrame implements java.awt.event.ActionListener { private UserRecord root; Wages myWages = new Wages("Wages"); Button ok = new Button("OK"); Button cancel = new Button("Cancel"); Label user = new Label("Username:"); Label pass = new Label("Password:"); TextField userField = new TextField(); TextField passwordField = new TextField(); JPanel buttonPanel = new JPanel(); JPanel inputPanel = new JPanel(); JPanel resultPanel = new JPanel(); int tries = 0; String username; String password;
public Login() { ok.setActionCommand("1"); cancel.setActionCommand("2"); ok.addActionListener(this); cancel.addActionListener(this); inputPanel.add(userField); inputPanel.add(passwordField);
inputPanel.setLayout(new GridLayout(1,1)); resultPanel.add(user); resultPanel.add(pass); resultPanel.setLayout(new GridLayout(1,1));
buttonPanel.add(ok); buttonPanel.add(cancel); buttonPanel.setLayout(new GridLayout(1,1)); getContentPane().add(resultPanel); getContentPane().add(inputPanel);
getContentPane().add(buttonPanel); getContentPane().setLayout(new GridLayout(3,2)); load();
passwordField.setEchoChar('*'); }
/** * Invoked when an action occurs. */ public void actionPerformed(java.awt.event.ActionEvent e) {
String X = e.getActionCommand(); String action = new String(); char command = X.charAt(0);
switch (command) { case '1': if (passwordchk()){ myWages.setSize(800, 600); myWages.show();
} else { JOptionPane.showMessageDialog(null, "Error, enter username and password again", "Error",JOptionPane.ERROR_MESSAGE); tries++; if (tries == 3){ System.exit(0); userField.setText(""); passwordField.setText(""); } } break; case '2': System.exit(0); break; } } public void addnode(String name, String password) { UserRecord theNode = new UserRecord( name, password, null ); theNode.setNext( root ); root = theNode;
} public void load(){ try { String userfile = "c:\\ReadinAndWritin.NBi"; ObjectInputStream userin = new ObjectInputStream(new FileInputStream(userfile)); String[][] info = (String[][]) userin.readObject(); userin.close(); username = info[0][0]; password = info[0][1]; addnode(username,password); } catch (IOException e) { } catch (Exception e) { } } public static void main(String[] args) { Login window = new Login();
window.setTitle("Log In"); window.setSize(250, 150); window.setVisible(true);
} public boolean passwordchk(){ boolean passed = false; String usernameField = userField.getText(); String passField = passwordField.getText(); if ((usernameField.equals("default")) & (passField.equals("firsttime"))) { passed = true; } else { UserRecord temp; temp = root; while (temp != null) {
if ((usernameField.equals(username)) & (passField.equals(password))) { passed = true; } temp = temp.getNext(); }
} return passed; }
}
As you can see, if the password is correct (case 1), it will show up another class. So, i want to hide this logging applet. how do i do it? thank you
|
|