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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:45:07+00:00 2026-06-15T07:45:07+00:00

I want to make other class frame setvisible(false) when button is pressed. There is

  • 0

I want to make other class frame setvisible(false) when button is pressed.

There is a class called DisplayScore and this class gets getContentPane().add(new ScoreInfo()); from ScoreInfo class.
Reason for spliting into two class is because DisplayScore extends JFrame and ScoreInfo extends JPanel.
Anyway

In ScoreInfo when button is pressed I want to call up other frame and close the DisplayScore frame. If I do this.setVisible(false);, only the Panel disappear, and the frame which is made from DisplayScore(), remains.

So..my question is how handle that from ScoreInfo class?
Check out the buttom part. actionPerformed method.

public class ScoreInfo extends JPanel implements ActionListener
{
        JButton btnBack;

public ScoreInfo()
{


    JTextArea ta = new JTextArea();
    ta.setForeground(Color.white);
    ta.setFont(new Font("Serif", Font.ITALIC+Font.BOLD, 16));
    ta.setBackground(Color.darkGray);

    try
    {
        ta.read(new FileReader("data/scores4.txt"),null);
    }
    catch(IOException ioe)
    {
        System.out.print("ERROR: Could not read file \"");
    }


    btnBack = new JButton("MAIN");
    btnBack.setSize(10,10);
    btnBack.setBackground(Color.darkGray);
    btnBack.setFont(new Font("Courier New", Font.ITALIC+Font.BOLD, 15));
    btnBack.setForeground(Color.black);

    JPanel score = new JPanel();
    score.setLayout(new BorderLayout());
    JButton btnScore = new JButton("H I G H  S C O R E");
    btnScore.setBackground(Color.BLACK);
    btnScore.setFont(new Font("Courier New", Font.ITALIC+Font.BOLD, 48));
    btnScore.setForeground(Color.white);

    JLabel score_tab = new JLabel("   N A M E  " + "  S C O R E  " + "  C O M B O  ");
    score_tab.setFont(new Font("Courier New", Font.ITALIC+Font.BOLD, 35));


    score.add(btnBack, BorderLayout.WEST);
    score.add(btnScore, BorderLayout.CENTER);
    score.add(score_tab, BorderLayout.SOUTH);

    JPanel panel = new JPanel();
    panel.setBackground(Color.darkGray);
    panel.setPreferredSize(new Dimension(800, 380));
    panel.setLayout(new BorderLayout());
    panel.add(score, BorderLayout.NORTH);
    //panel.add(backpnl, BorderLayout.WEST);
    panel.add(ta, BorderLayout.CENTER);

    add(panel, score);

    btnBack.addActionListener(this);

    }

public void actionPerformed(ActionEvent evt){
    if(evt.getSource()==btnBack){

        //want to make DisplayScore.setVisible(false); 
        //this.setVisible(false);
        MainFrame mf = new MainFrame();
        mf.pack();
        mf.setSize(640,480);
        mf.setLocation(400,0);
        mf.setResizable(false);
        mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mf.setVisible(true);

    }
}

}

  • 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-15T07:45:08+00:00Added an answer on June 15, 2026 at 7:45 am

    You could:

    • Pass a reference of the parent frame to the panel. I think this is a little dirty, but that’s just me.
    • Use SwingUtilities.getWindowAncestor(Component) to find the parent window of the current component. You can then call setVisible on it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make something like this... :LoopBegin if ???? goto End some other
I want to make multiple instances of this class. public class Worker { private
I want to make an app that can receive broadcast when other apps on
I want to make an console application of c which can run other applications
I want to make a simple program that sends random keystrokes to my other
Okay so I want to make an application that launches other applications. However, the
Hy. i want to make 1 multithreaded application probably in C# and other applications
I have two non-overlapping sets of types and want to make other set which
I have a main JFrame. There is a button inside the frame. When I
Here is what i want to do.. I have a class called userInfo. I

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.