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

  • SEARCH
  • Home
  • 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 8057007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:53:30+00:00 2026-06-05T08:53:30+00:00

I’ve been programming for quite a long time in PHP and other web programming

  • 0

I’ve been programming for quite a long time in PHP and other web programming languages but I’m really new to Java. And as I’ve been using a procedural approach when programming in PHP I’m quite new to OOP as well. Now I’m following a very basic Java tutorial.

I have this code for displaying to different “bank accounts”:

public class UseAccount extends JFrame {

public static void main(String[] args) {

    Account myAccount = new Account();
    Account yourAccount = new Account();

    myAccount.name = "Jimmy";  
    myAccount.address = "Arjeplogsvägen 1";
    myAccount.balance = 1250.70;

    yourAccount.name = "Greg Giraldo";
    yourAccount.address = "Fishermans friend's 4";
    yourAccount.balance = -5820.30;

    myAccount.display();
    System.out.println();
    yourAccount.display();
}
}

And here is the “Account” class:

public class Account{
    String name;
    String address;
    double balance;

    void display() {
        System.out.print(name);
        System.out.print(" (");
        System.out.print(address);
        System.out.print(") has $");
        System.out.print(balance);
    }     
}

This works really well. but now I want to output this information to a JTextArea. So I’ve written this code for the UseAccount class:

import java.awt.*;
import javax.swing.*;

public class UseAccount extends JFrame {
        JTextArea output = new JTextArea();

    public UseAccount() {
        setLayout(new BorderLayout());
        add(output, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
    UseAccount frame = new UseAccount();
    frame.setTitle("Account");
    frame.setSize(500,400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    Account myAccount = new Account();
    Account yourAccount = new Account();

    myAccount.name = "Jimmy";  
    myAccount.address = "Arjeplogsvägen 1";
    myAccount.balance = 1250.70;

    yourAccount.name = "Greg Giraldo";
    yourAccount.address = "Fishermans friend's 4";
    yourAccount.balance = -5820.30;

    myAccount.display();
    System.out.println();
    yourAccount.display();
    }
}

And then I was trying to make the “Account” class extend the “UseAccount” class and then use output.append(“the_text”) for displaying the text. But this obviously doesn’t work:

public class Account extends UseAccount{
    String name;
    String address;
    double balance;

    void display() {
        output.append(name);
        output.append(" (");
        output.append(address);
        System.out.print(") has $");
        System.out.print(balance);
    }     
}

I did not change every system.out.print() to output.append as it isn’t working anyway.

I’m wondering how to access and change the text of my textarea(“output”) from this other class?

I hope someone will be able to help me with this little problem.

I do know that similiar questions have been asked here earlier. And I have tried to look at the solutions given to those questions to solve my problem. But most of the other questions have been too complicated for me to understand what it was all about. Therefore I now try to post my own question.

  • 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-05T08:53:32+00:00Added an answer on June 5, 2026 at 8:53 am

    Inheritance is not the answer to everything, and here is is not the answer at all. Inheritance should model “is-a”, and by no stretch of the imagination is an Account a UseAccount.

    Instead, just change the signature of display() to take a JTextArea as an argument; then in the display() code you’ll have a JTextArea to work with. When you call display(), pass the JTextArea in.

    In other words:

    void display(JTextArea ta) {
        ta.append(name);
        ...
    

    and then

    // "frame" is the UseAccount object that contains the JTextArea variable `output`
    myAccount.display(frame.output);
    

    Most of the time, the right question is not “How can X get access to part of Y”, but rather “How can Y give access to part of itself to X?”

    One final note: small effort put into naming variables well really pays off.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,

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.