The Artima Developer Community
Sponsored Link

Java Answers Forum
PLS NEED HELP ASAP!

7 replies on 1 page. Most recent reply: Oct 6, 2003 4:28 AM by sindu

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 7 replies on 1 page
John

Posts: 13
Nickname: icej
Registered: Sep, 2003

PLS NEED HELP ASAP! Posted: Oct 5, 2003 9:55 PM
Reply to this message Reply
Advertisement
I want to be able to make the applet invisible when it opens a class.
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.ad d(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.se tLayout(new GridLayout(1,1));

getContentPane().add(resultPanel);
getContentPane().add(inpu tPanel);

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("");
}
}

brea k;
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?
i tried many methods but i kept getting this error message: cannot make a static reference to a non-static....
can someone pls help me, i really need it ASAP
thank you


sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 5, 2003 10:22 PM
Reply to this message Reply
"cannot make a static reference to a non-static.... "

If this is the error message then make the particular method or variable which is giving the error as static or try to call that from inside main method. The best is to make it static.

eg.
if its a method:
public static returntype methodname{
}

if its a variable:
public static variablename

John

Posts: 13
Nickname: icej
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 5, 2003 10:53 PM
Reply to this message Reply
i still don't know how to do it. can someone pls specify where do i have to put the code and what code pls. i already tried yesterday for 2 hours and today another hour.
thank you

sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 5, 2003 11:08 PM
Reply to this message Reply
Post the full error message.

John

Posts: 13
Nickname: icej
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 5, 2003 11:45 PM
Reply to this message Reply
i tried to put Login.setVisible(false); in (Case 1)
and it gives
cannot make a static reference to the instance method named setVisible for class java.awat.Component with arguments (boolean).
i don't know if you do it like that or not

sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 6, 2003 1:21 AM
Reply to this message Reply
I have made some changes.I have put comment as new wherever changes are made for ur referrence.

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 
{
static Login window;/*new*/
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.ad d(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.se tLayout(new GridLayout(1,1));
 
getContentPane().add(resultPanel);
getContentPane().add(inpu tPanel);
 
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()){
window.setVisible(false);/*new*/
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("");
}
}
 
brea k;
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) {
window = new Login();/*new*/
 
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;
 
}
 
 
}

John

Posts: 13
Nickname: icej
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 6, 2003 1:31 AM
Reply to this message Reply
sindu THANK YOU SOOOOO MUCH.

sindu

Posts: 15
Nickname: sindu
Registered: Sep, 2003

Re: PLS NEED HELP ASAP! Posted: Oct 6, 2003 4:28 AM
Reply to this message Reply
U r welcome john but try to understand why its working now and not before.

Flat View: This topic has 7 replies on 1 page
Topic: code required for nested for loops Previous Topic   Next Topic Topic: J2ME with DB2

Sponsored Links



Google
  Web Artima.com   

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