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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:27:41+00:00 2026-06-09T15:27:41+00:00

I am using to different classes: one holding a main JFrame with a button,

  • 0

I am using to different classes: one holding a main JFrame with a button, and one holding a new JFrame that is called upon at a button press.

if( event.getSource() == noteBtn ) { MiniPad.pad(); return;}

(MiniPad.pad() references the class and pad() method on the new JFrame)

When I removeAll() on the JPanel that hosts the button, and then revalidate() and repaint(), the button opens the JFrame multiple times, which isn’t what I want it to do at all.

Is there a way to tell the MiniPad class that you can’t have more than one copy of the JFrame open at any one time? I extend the JFrame by the way, in case that’s any help.

  • 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-09T15:27:42+00:00Added an answer on June 9, 2026 at 3:27 pm

    Edit: Everything below is valid programming knowledge, but you might also want to consider having MiniPad extend the JDialog class instead. I haven’t used it before, but its implementation looks a lot like JFrame. You might not actually have to change much in your MiniPad class. The documentation is here: http://docs.oracle.com/javase/7/docs/api/javax/swing/JDialog.html

    If you’re wondering why, check out Andrew Thompson’s post here.

    —

    From what I understood of your question, MiniPad extends JFrame, and the pad() method creates a new instance of the MiniPad class. The simplest solution would be to turn the MiniPad class (at least through the pad() method) into a singleton. A singleton is a type of class where only one instance (or object) can exist at any given time. By calling a static method (in this case pad()) you check to see if an instance of the object already exists; if it does, simply use that existing object:

    public class MiniPad extends JFrame {
    
        //whatever code you have
    
        private static MiniPad padInstance = null; //the singleton instance of your MiniPad
    
        public static MiniPad pad() {
            if(padInstance == null)
                padInstance = new MiniPad();
            //If you want to reset the object every time you call the method for whatever reason, do it here
            pad.setVisible(true); // I believe this is all you want to do
        }
    }
    

    This should do what you want. By calling the pad() method, only one MiniPad will ever show up.

    However, if I read your question wrong, let me know and I will revise my answer.

    Info on singletons:
    http://en.wikipedia.org/wiki/Singleton_pattern

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

Sidebar

Related Questions

I'm trying to learn how to set variables for different classes using one main
I have Three different classes that all need to use instances of one class.
I understand the IOC concept, which we can mix-and-match different classes using wiring. Every
I have 2 different group page with 2 look alike classes which using the
I have a thread that downloads some images from internet using different proxies. Sometimes
I'm interested about using 2 different classes in 2 different environment. Both classes should
I'm using VS2008 C#.NET. I created 3 different classes of libraries in 3 projects.
I have a number of classes doing different things but using the same Singleton
If I have 2 different classes with name User , say one in FooModule
Yes, I'm new to c#! :) i'm using .Net4 VS2010. I have Three classes

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.