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 9123401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:19:50+00:00 2026-06-17T06:19:50+00:00

I’m writing a small text-based game for my class. The navigation is simple, in

  • 0

I’m writing a small text-based game for my class. The navigation is simple, in which the player clicks buttons to enter a different part. All of these parts are separated into their own blocks of code. I’ve set up only two parts so far, each of them being able to reach one another through buttons. Basically:

private void level1() {
//Stuff here, player clicks a button which runs "level2();"
}

private void level2() {
//Stuff here, player clicks a button which runs "level1();"
}

So that works just fine, but after some clicking back and forth between 1 & 2, the program starts to run very slow. Task Manager reports about 700MB of memory usage.

I’m sure there’s something real obvious that I’m missing. I’m looking for a way for the user to be able to click many buttons, many times, and not make the program use so much resources. Help would be very much appreciated.

Edit: Some more code. Choice1-3 are the names for the buttons. Variables are already declared at the top of the program, and set up in the initialize part. They’re to be modified with each block of code, such as Scene1 and 2.

private void setScene1() // TITLE SCREEN
{
    TITLE.setText("Title Label");
    main.setText("Main text body for the game.");
    choice1.setText("Play");
    choice1.setBounds(10, 600, 996, 91); // This makes choice1 as large as
                                            // all three buttons combined.
    choice2.setEnabled(false);// There's only one option anyway.
    choice3.setEnabled(false);
    choice2.setVisible(false);
    choice3.setVisible(false);

    choice1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setScene2();
        }
    });

}

private void setScene2() // CHARACTER GENERATION SCENE
{
    TITLE.setText("Character Generation");
    main.setEnabled(false); // Disable & Hide the main text window, as
                            // Chargen requires a nicer looking interface.
    main.setVisible(false);
    choice2.setEnabled(true);
    choice2.setVisible(true);
    choice1.setBounds(10, 600, 996, 34); //Resizing the bottom portion to fit two buttons
    choice2.setBounds(10, 645, 996, 34);
    choice1.setText("Continue");
    choice1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            // Nothing here for now
        }
    });
    choice2.setText("Back to the Title Screen");
    choice2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            main.setEnabled(true);
            main.setVisible(true);
            setScene1();
        }
    });

}
  • 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-17T06:19:52+00:00Added an answer on June 17, 2026 at 6:19 am

    The problem seems to lie in the fact that you’re adding an ActionListener every time you switch scenes. The previous ActionListener is never going away, but you’re stacking more on top of it that do the same thing. Each one performs the same action, so when you press to switch scene, all the ActionListners that it now has will also go to switch scene. Your CPU will go up because there’s now 2^n ActionListeners waiting for input and there’s that many sitting in memory.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app for my school newspaper, which is run completely online
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.