The Artima Developer Community
Sponsored Link

Java Answers Forum
How can i hide an applet?

3 replies on 1 page. Most recent reply: Oct 7, 2003 2:24 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
John

Posts: 13
Nickname: icej
Registered: Sep, 2003

How can i hide an applet? Posted: Oct 4, 2003 9:30 PM
Reply to this message Reply
Advertisement
Hi,
i created a login applet which if the username and password is correct, it opens up a class by doing :
Wages myWages = new Wages("Wages");
and
myWages.show();
after the applet shows, i want to close the login applet but it won't let me. i already tried for 2 hours and i can't get to hide it or set.invisible. keeps giving me error because it is not static.
please help me
thank you


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: How can i hide an applet? Posted: Oct 5, 2003 10:35 AM
Reply to this message Reply
"close the login applet"

What do you mean "close"? Load a new HTML page? Hide the applet container? Clear the applet screen?

"keeps giving me error because it is not static"

This isn't helpful. All we can tell from that is that (probably) you're calling instance code from a static block. Post the error message and some code and we might be able to determine if that is the case.

John

Posts: 13
Nickname: icej
Registered: Sep, 2003

Re: How can i hide an applet? Posted: Oct 5, 2003 11:02 AM
Reply to this message Reply
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

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: How can i hide an applet? Posted: Oct 7, 2003 2:24 AM
Reply to this message Reply
Instead of adding the panels to contentPane

getContentPane().add(resultPanel);
getContentPane().add(inputPanel );

getContentPane().add(buttonPanel);

Add it to a panel say compPanel and addCompPanel to the contentPane

and call
wen u want to set its visibility to false...
compPanel.setVisible(false);


else dispose the current content pane once user is validated

Flat View: This topic has 3 replies on 1 page
Topic: OO Books using Java Previous Topic   Next Topic Topic: Graphics 2D sprayPaint stroke/brush needed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use