problem getting a simple logon program compiling
hello.
i have developed a simple logon program. when i try to compile the program, i get 5 errors (errors + code are shown below). what are causing these errors and how can they be fixed?
-jGRASP exec: javac -g E:\CP4B Project\LogOn.java
LogOn.java:50: cannot find symbol
symbol: variable logOn
logOn = null;
^
LogOn.java:72: cannot find symbol
symbol : method setVisible(boolean)
location: class User
setVisible(false);
^
LogOn.java:83: cannot find symbol
symbol : method setVisible(boolean)
location: class User
setVisible(false);
^
LogOn.java:109: cannot find symbol
symbol : method setVisible(boolean)
location: class Administrator
setVisible(false);
^
LogOn.java:120: cannot find symbol
symbol : method setVisible(boolean)
location: class Administrator
setVisible(false);
^
5 errors
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
publicclass LogOnextends JFrame{
JTextField jtfUN =new JTextField(20);
JPasswordField jtfPW =new JPasswordField(20);
JButton jbOK =new JButton("OK");
JButton jbCancel =new JButton("Cancel");
public LogOn(){
super("Welcome to Home Entertainment");
setSize(250, 250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp =new JPanel();
JLabel unLabel =new JLabel("Username: ");
JLabel pwLabel =new JLabel("Password: ");
jp.add(unLabel);
jp.add(jtfUN);
jp.add(pwLabel);
jp.add(jtfPW);
jp.add(jbOK);
jp.add(jbCancel);
setContentPane(jp);
pack();
jbOK.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
User u =new User();
u.doLogOn();
u.username = jtfUN.getText().trim();
u.password =new String(jtfPW.getPassword());
Administrator a =new Administrator();
a.doLogOn();
a.username = jtfUN.getText().trim();
a.password =new String(jtfPW.getPassword());
}
});
jbCancel.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
logOn =null;
setVisible(false);
}
});
}
publicstaticvoid main(String[] args){
LogOn logOn =new LogOn();
}
}
class User{
String username;
String password;
String[] userUsernameArray ={"Ann Smyth","John Murphy"};
String[] userPasswordArray ={"1","2"};
publicvoid doLogOn(){
int i, j;
for(i = 0; i < userUsernameArray.length; i++){
if(username.equals(userUsernameArray[i])){
setVisible(false);
//UserMainMenu umm = new UserMainMenu();
//umm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null,"Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
for(j = 0; j < userPasswordArray.length; j++){
if(password.equals(userPasswordArray[j])){
setVisible(false);
//UserMainMenu umm = new UserMainMenu();
//umm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null,"Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
}
}
class Administrator{
String username;
String password;
String[] adminUsernameArray ={"Administrator"};
String[] adminPasswordArray ={"0"};
publicvoid doLogOn(){
int k, l;
String username;
String password;
String[] adminUsernameArray ={"Administrator"};
String[] adminPasswordArray ={"0"};
for(k = 0; k < adminUsernameArray.length; k++){
if(username.equals(adminUsernameArray[k])){
setVisible(false);
//AdminMainMenu amm = new AdminMainMenu();
//amm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null,"Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
for(l = 0; l < adminPasswordArray.length; l++){
if(password.equals(adminPasswordArray[l])){
setVisible(false);
//AdminMainMenu amm = new AdminMainMenu();
//amm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null,"Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
}
}
I'm going to do you a huge favour and not tell you. No, really. The compiler is telling you exactly what's wrong, you just need the confidence to trust that you've understood it - it's not as hard as it looks!
What do the errors all say here? They're all saying basically the same thing - what is it?
(work with me on this, don't just get annoyed because I'm not answering your question - it'll be worth it)
in line no 43 ur logOn = null is appearing first than where u r initialising it
to be more specific ur logOn is not initialised in ur LogOn class
hello anya_aa.
i did what you told me to do. i only got 4 errors this time (both errors + code are shown below). that is because i put the logOn = null; in the main() method in the LogOn class (it is not in the constructor this time, which is a help). what am i doing wrong this time? will removing the setVisible(false); methods from the User + Administrator classes and putting only one setVisible(false); method in as the last statement in the jbOK.addActionListener(new ActionListener(){} method reduce the number of errors i get when i compile the program?
-jGRASP exec: javac -g E:\CP4B Project\LogOn.java
LogOn.java:73: cannot find symbol
symbol : method setVisible(boolean)
location: class User
setVisible(false);
^
LogOn.java:84: cannot find symbol
symbol : method setVisible(boolean)
location: class User
setVisible(false);
^
LogOn.java:110: cannot find symbol
symbol : method setVisible(boolean)
location: class Administrator
setVisible(false);
^
LogOn.java:121: cannot find symbol
symbol : method setVisible(boolean)
location: class Administrator
setVisible(false);
^
4 errors
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LogOn extends JFrame{
JTextField jtfUN = new JTextField(20);
JPasswordField jtfPW = new JPasswordField(20);
JButton jbOK = new JButton("OK");
JButton jbCancel = new JButton("Cancel");
public LogOn(){
super("Welcome to Home Entertainment");
setSize(250, 250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
JLabel unLabel = new JLabel("Username: ");
JLabel pwLabel = new JLabel("Password: ");
jp.add(unLabel);
jp.add(jtfUN);
jp.add(pwLabel);
jp.add(jtfPW);
jp.add(jbOK);
jp.add(jbCancel);
setContentPane(jp);
pack();
jbOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
User u = new User();
u.doLogOn();
u.username = jtfUN.getText().trim();
u.password = new String(jtfPW.getPassword());
Administrator a = new Administrator();
a.doLogOn();
a.username = jtfUN.getText().trim();
a.password = new String(jtfPW.getPassword());
}
});
jbCancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
}
});
}
public static void main(String[] args){
LogOn logOn = new LogOn();
logOn = null;
}
}
class User{
String username;
String password;
String[] userUsernameArray = {"Ann Smyth", "John Murphy"};
String[] userPasswordArray = {"1", "2"};
public void doLogOn(){
int i, j;
for(i = 0; i < userUsernameArray.length; i++){
if(username.equals(userUsernameArray[i])){
setVisible(false);
//UserMainMenu umm = new UserMainMenu();
//umm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
for(j = 0; j < userPasswordArray.length; j++){
if(password.equals(userPasswordArray[j])){
setVisible(false);
//UserMainMenu umm = new UserMainMenu();
//umm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
}
}
class Administrator{
String username;
String password;
String[] adminUsernameArray = {"Administrator"};
String[] adminPasswordArray = {"0"};
public void doLogOn(){
int k, l;
for(k = 0; k < adminUsernameArray.length; k++){
if(username.equals(adminUsernameArray[k])){
setVisible(false);
//AdminMainMenu amm = new AdminMainMenu();
//amm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
for(l = 0; l < adminPasswordArray.length; l++){
if(password.equals(adminPasswordArray[l])){
setVisible(false);
//AdminMainMenu amm = new AdminMainMenu();
//amm.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Error\n\nYou have entered an incorrect username and/or password\nPlease try again", null, JOptionPane.ERROR_MESSAGE);
}
}
}
}
hello anya_aa.
i've managed to sort out my problem with the login program. i got it compiled and running anyway.
i have done more modifications to the ViewOrder.java program, which meant that i did all that hunter9000 told me to do - to the best of my ability. when i run the program this time, i pressed the View Order button. when i pressed the button, no data from the Order.txt file appeared in the text area at all. would you have any idea of where i am going wrong this time?
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class ViewOrder extends JFrame{
JPanel pnlText, pnlBody, pnlFooter;
JButton btnViewOrder;
JButton btnReturnToOrderSystem;
JLabel jl;
JTextArea jtaDescription = new JTextArea();
Container contentpane;
public ViewOrder(){
super("View Order");
contentpane = getContentPane();
contentpane.setLayout(new BorderLayout());
pnlText = new JPanel();
pnlBody = new JPanel();
pnlFooter = new JPanel();
jtaDescription = new JTextArea();
jtaDescription.setFont(new Font("Serif", Font.PLAIN, 14));
// Set lineWrap and wrapStyleWord true for the text area
jtaDescription.setLineWrap(true);
jtaDescription.setWrapStyleWord(true);
jtaDescription.setEditable(false);
pnlBody.add(jtaDescription);
// Create a scroll pane to hold the text area
JScrollPane scrollPane = new JScrollPane(jtaDescription);
// Set BorderLayout for the panel, add label and scrollpane
pnlBody.add(scrollPane, BorderLayout.CENTER);
jl = new JLabel("Text retrieved from file:");
btnViewOrder = new JButton("View Order");
btnReturnToOrderSystem = new JButton("Return to Order System Menu");
pnlText.add(jl);
pnlFooter.add(btnViewOrder);
pnlFooter.add(btnReturnToOrderSystem);
contentpane.add(pnlText,BorderLayout.NORTH);
contentpane.add(pnlBody,BorderLayout.CENTER);
contentpane.add(pnlFooter,BorderLayout.SOUTH);
pack();
setVisible(true);
btnViewOrder.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//Read from file
try{
String inputFileName = "Order.txt";
File inputFile = new File(inputFileName);
FileInputStream in = new FileInputStream(inputFile);
BufferedReader iS = new BufferedReader(new InputStreamReader(in));
String iL = "";
iL = iS.readLine();
setDescription(iL);
iS.close();
}
catch(java.io.IOException ex){
System.out.println("Cannot read from file");
}
}
});
btnReturnToOrderSystem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
//OrderSystem os = new OrderSystem();
//os.setVisible(true);
}
});
}
/** Set the text description */
public void setDescription(String iL) {
jtaDescription.getPreferredSize();
jtaDescription.setText(iL);
jtaDescription.append(iL);
}
public static void main(String[] args){
new ViewOrder();
}
}
