Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:01:03+00:00 2026-06-03T03:01:03+00:00

I’m a newbie Java guy so I’m probably doing this entire thing completely wrong.

  • 0

I’m a newbie Java guy so I’m probably doing this entire thing completely wrong. I have to do this giant project for software engineering class. The code is about 2,000 lines long so this is skeleton code

public class BookRental extends JFrame{
   public Client currentClient = new Client(); // creating client object
   //rest of declared variables.

   public class Client{                        //Client class containing all get/set methods for each variable
   private username;
   private void setUsername(String u){
      username = u;
   }
   public String getUsername(){
      return username;
   }


   public class LoginPanel extends JPanel{}    //Panel to show and receive login info.
   public class RegisterPanel extends JPanel{} //Panel to register.
   public class MenuPanel extends JPanel{      //Panel showing main menu.
      //At this point currentClient will contain values
      public ClientInfoPanel(){
         initComponents();
      }
      private void initComponents(){
         infoPanelUserName = new JLabel();
         infoPanelFullName.setText("Currently logged in as: " + currentClient.getUsername());
      }
      private JLabel infoPanelUserName;
    }
   public class ClientInfoPanel extends JPanel{} //Panel to print currentClient info to screen using JLabel objects

   private void ViewClientInfoButtonActionPerformed(event){  // Using button in Menu Panel to setVisibility of clientInfoPanel to (true)
      //At this point there will be a value for currentClient
      clientInfoPanel = new ClientInfoPanel();
      this.add(clientInfoPanel);
      menuPanel.setVisible(false);
      clientInfoPanel.setVisible(true);
   }
   public BookRental(){initComponents();} //Constructor
   private void initComponents(){}             // Creates all panels and sets visibility off, besides login

   public static void main(String args[]){
       new BookRental().setVisible(true);
   }

}

I already am pretty sure I am doing this COMPLETELY wrong, however my question is why can’t I access currentClient inside of ClientInfoPanel? Say for this JLabel:

infoPanelUserName.setText("Currently logged in as: " + currentClient.getUsername());

The ClientInfoPanel recognizes currentClient exists and that the getUsername() method exists, however it prints:

“Currently logged in as: “

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:01:03+00:00Added an answer on June 3, 2026 at 3:01 am

    The code you showed looks fine, so the problem is somewhere else, or this code is not representative of what you have. Also, you ARE accessing currentClient successfully, unless you’re getting a NullPointerException or catching it somewhere, then the .getUsername() call IS resolving. So the problem is actually with .getUsername(), somehow username is uninitialized when you call .getUsername();

    As a test, can you call .setUsername() on currentClient right before you call .getUsername()? That should help us narrow down the problem, isolate it to either the class access or the variable being initialized.

    Also, do you know how to debug with breakpoints? You mentioned you’re new, so you might not know this is possible. If you’re using Eclipse (or another good IDE) you can set breakpoints and run the program in DEBUG build, then the program will freeze when it hits the line you set a breakpoint on, and you can watch as the program moves line by line, and see the variables as they are updated by the program. Google java debug tutorial. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.