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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:32:57+00:00 2026-05-31T00:32:57+00:00

Ive created two frames my main frame is Home and the second one is

  • 0

Ive created two frames my main frame is Home and the second one is Selectie
On home there is a button which open the frame selectie, but i want when i click this button the main frame home wil dissapear and only selectie will be shown. The code for the button ive make in a other package and i dont want it in the same class as my main (home)

Code from Home:

package View;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.io.File;


import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

import javax.swing.JPanel;

import Controller.HomeController;


import music.PlaySound;

public class Home extends JFrame {

    private JLabel label, label1, label2;
    private JPanel panel;
    private JButton logo, logo1, logo2, logo3, logo4, logo5, selectie;
    private Container window = getContentPane();
    private HomeController Controller;

    public Home (){
        initGUI();
        Controller = new HomeController();
    }
    public void addHomeListener(ActionListener a){
        selectie.addActionListener(a);
    }
    public void initGUI(){

        setLayout(null);
        setTitle("");
        setPreferredSize(new Dimension(800,600));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        label = new JLabel();       
        label.setBounds(0, 0, 266, 800);
        label.setBackground(Color.WHITE);
        label.setOpaque(true);
        window.add(label);

        label1 = new JLabel();
        label1.setBounds(267, 0, 266, 800);
        label1.setBackground(Color.RED);
        label1.setOpaque(true);
        window.add(label1);

        label2 = new JLabel();
        label2.setBounds(533, 0, 266, 800);
        label2.setBackground(Color.WHITE);
        label2.setOpaque(true);
        window.add(label2);

        logo = new JButton(new ImageIcon("../Ajax/src/img/logotje.gif"));
        logo.setBorderPainted(false);
        logo.setBounds(40, 150, 188, 188);
        label1.add(logo);

        logo1 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
        logo1.setBorderPainted(false);
        logo1.setBounds(10, 50, 82, 82);
        label1.add(logo1);

        logo2 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
        logo2.setBorderPainted(false);
        logo2.setBounds(92, 20, 82, 82);
        label1.add(logo2);

        logo3 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
        logo3.setBorderPainted(false);
        logo3.setBounds(174, 50, 82, 82);
        label1.add(logo3);

        logo4 = new JButton(new ImageIcon("../Ajax/src/img/shirt.png"));
        logo4.setBorderPainted(false);
        logo4.setBounds(50, 50, 135, 182);
        label.add(logo4);

        logo5 = new JButton(new ImageIcon("../Ajax/src/img/uitshirt.png"));
        logo5.setBorderPainted(false);
        logo5.setBounds(65, 50, 138, 190);
        label2.add(logo5);

        selectie = new JButton("Selectie");
        selectie.setBounds(60, 500, 99, 25);
        selectie.setActionCommand("selectie");
        label.add(selectie);

        pack();

        addHomeListener(new HomeController());
    }

}

Code from the button:

package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import View.Home;
import View.Selectie;

public class HomeController implements ActionListener {

    public void actionPerformed (ActionEvent e){
            Selectie selectie = new Selectie();
            selectie.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-05-31T00:32:59+00:00Added an answer on May 31, 2026 at 12:32 am

    Please do give valid attention to what @kleopatra and @mKorbel, has to say, they are very much right in pointing that out to you to make things easier.

    Here I had added some comments in the code, do check this out :

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionListener;
    import java.io.File;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    import javax.swing.JPanel;
    
    //import Controller.HomeController;
    
    
    //import music.PlaySound;
    
    public class Home extends JFrame {
    
        private JLabel label, label1, label2;
        private JPanel panel;
        private JButton logo, logo1, logo2, logo3, logo4, logo5, selectie;
        private Container window = getContentPane();
        private HomeController Controller;
    
        public Home (){
            initGUI();
        }
        public void addHomeListener(ActionListener a){
            selectie.addActionListener(a);
        }
        public void initGUI(){
    
            setLayout(null);
            setTitle("");
            setPreferredSize(new Dimension(800,600));
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            label = new JLabel();       
            label.setBounds(0, 0, 266, 800);
            label.setBackground(Color.WHITE);
            label.setOpaque(true);
            window.add(label);
    
            label1 = new JLabel();
            label1.setBounds(267, 0, 266, 800);
            label1.setBackground(Color.RED);
            label1.setOpaque(true);
            window.add(label1);
    
            label2 = new JLabel();
            label2.setBounds(533, 0, 266, 800);
            label2.setBackground(Color.WHITE);
            label2.setOpaque(true);
            window.add(label2);
    
            logo = new JButton(new ImageIcon("../Ajax/src/img/logotje.gif"));
            logo.setBorderPainted(false);
            logo.setBounds(40, 150, 188, 188);
            label1.add(logo);
    
            logo1 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
            logo1.setBorderPainted(false);
            logo1.setBounds(10, 50, 82, 82);
            label1.add(logo1);
    
            logo2 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
            logo2.setBorderPainted(false);
            logo2.setBounds(92, 20, 82, 82);
            label1.add(logo2);
    
            logo3 = new JButton(new ImageIcon("../Ajax/src/img/Ster.png"));
            logo3.setBorderPainted(false);
            logo3.setBounds(174, 50, 82, 82);
            label1.add(logo3);
    
            logo4 = new JButton(new ImageIcon("../Ajax/src/img/shirt.png"));
            logo4.setBorderPainted(false);
            logo4.setBounds(50, 50, 135, 182);
            label.add(logo4);
    
            logo5 = new JButton(new ImageIcon("../Ajax/src/img/uitshirt.png"));
            logo5.setBorderPainted(false);
            logo5.setBounds(65, 50, 138, 190);
            label2.add(logo5);
    
            selectie = new JButton("Selectie");
            selectie.setBounds(60, 500, 99, 25);
            selectie.setActionCommand("selectie");
            label.add(selectie);
    
            pack();
    
            /*
             * You are making a new object again,
             * when you already had declared it as 
             * an instance Variable. So I used the 
             * one declared as instance variable..
             * To this we will send the object of Home
             * class, means the object of this class..
             * And as we know that object of the 
             * class we are in is by default known 
             * as this, so passing this to HomeController class.
             */
            Controller = new HomeController(this);
            addHomeListener(Controller);
    
            setVisible(true);
        }
    
        public static void main(String... args)
        {
            javax.swing.SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new Home();
                }
            });
        }
    }
    
    class HomeController implements ActionListener {
    
        /*
         * Here we declared a Home class's variable,
         * that we will use to dispose that JFrame.
         */
        private Home home;
    
        public HomeController(Home home)
        {
            this.home = home;
        }
    
        public void actionPerformed (ActionEvent e){
    
                home.dispose();
                Selectie selectie = new Selectie();
                selectie.setVisible(true);
        }
    }
    
    class Selectie extends JFrame
    {
        public Selectie()
        {
            initGUI();
        }
    
        public void initGUI()
        {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setLocationByPlatform(true);
    
            setSize(300, 300);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created two EmacsW32 frames, one for each of my monitors. I want to
I've created two classes, with one of them having an implicit cast between them:
I've created two UserControls, a ValidationManager and a ValidationOutput. On a given form there
I've created a report in SSRS with two report parameters. I'd like the second
I've created a simple iPhone app which has two .xib files. In the app
I've created a custom control which consists of two radio buttons with their appearance
I asked this before, but only theoretically, without an SSCCE. Now, I've created one,
Basically I have created two MATLAB functions which involve some basic signal processing and
I've created two functions to load expanded views of a month in the archive
I've created two entities (simplified) in C#: class Log { entries = new List<Entry>();

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.