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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:20:13+00:00 2026-06-04T01:20:13+00:00

I have a class Maze (extends JPanel). I want to make a new button,

  • 0

I have a class Maze (extends JPanel). I want to make a “new” button, that replace a variable of this class by new variable.

    btnNewMaze.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            maze.repaint();
            maze = new Maze((int) xSpinner.getValue(), (int) ySpinner.getValue());  
            maze.repaint();
        }
    });

Other buttons work ok.
But this doesn’t work correctly – doesn`t repaint, methods thorw exceptions, etc.
How can I solve this or replace with another code?

  • 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-04T01:20:15+00:00Added an answer on June 4, 2026 at 1:20 am

    Somehow I think that what you want is that a maze object which is already added to a visible container (a JPanel, for example) be substituted for a new instance of Maze when a button is pressed.

    If that is the case and if this “maze” object was already added to a container (a JPanel, for example), then, when you execute the code you provided, i.e.: maze = new Maze(…), your old maze object would remain added to the container and would remain unaffected. The container would still hold an inner reference to the old maze object.

    In fact, when the code maze = new Maze(…) is executed, what happens isn’t the former maze object substitution. Actually, what happens is that your reference variable maze is pointed to the new Maze() object, while the old instance remains attached to the container.

    If what you want is the substitution of an old maze object already added to a container, then you should remove it from the container and add the new one.

    This all may not be the case, but it’s what I was able to understand given the provided information. Please, give us more details (a whole class or method, the exceptions that are thrown, what exactly you’re trying to do, and so on).

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

Sidebar

Related Questions

I have class B that has class A, this is simplified version of class
I am creating a maze game. For that I have created 4 separate class
This is quite odd, because I have a Character class that can access Frame.dimension.getWidth();
I have class (MyCustomWebView) that extend webview can i do something like this ?
Hello I have a class with a function that returns a pointer: int* Maze::GetStart()
I have class A: public B { ...} vector<A*> v; I want to do
I have class that represents users. Users are divided into two groups with different
i have class named Group i tried to test configuration: var cfg = new
I want to build a maze with player that move on the maze board.
I have class ParentClass that observes an NSNotification. ParentClass handles the notification. ChildClass inherits

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.