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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:19:24+00:00 2026-06-06T05:19:24+00:00

I have the following code which creates a simple window with two buttons which

  • 0

I have the following code which creates a simple window with two buttons which are in turn suppose to open up a window each – the main window opens up just fine but when you click on the buttons nothing happens…

package presentation;

import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ShowInventory extends JFrame {

    /**
     * 
     */
    private static final long serialVersionUID = 7479750059244371227L;
    private JPanel contentPane;
    private JButton catBtn = new JButton ("Display inventory by category");
    private JButton allBtn = new JButton ("Display all inventory");


    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ShowInventory frame = new ShowInventory();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Exception - Sorry");
                }
            }
        });
    }

    /**
     * Default - details to be added
     */
    public ShowInventory() { // title bar name

        // layout here
        Container container = getContentPane();
        FlowLayout layout = new FlowLayout();
        container.setLayout(layout);
        layout.setAlignment(FlowLayout.CENTER);
        container.add(new JButton("Display inventory by category"));
        container.add(new JButton("Display all inventory"));


        catBtn.addActionListener (new ActionListener() {
            public void actionPerformed (ActionEvent event) {
                // controller code
                ShowByCategory frame = new ShowByCategory();
                frame.setVisible(true);
            }
        });



        allBtn.addActionListener (new ActionListener() {
            public void actionPerformed (ActionEvent event) {
                // controller code
                ShowAllInventory frame = new ShowAllInventory();
                frame.setVisible(true);
            }
        });

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        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-06T05:19:26+00:00Added an answer on June 6, 2026 at 5:19 am

    You probably need to replace those lines (which create brand new buttons):

    container.add(new JButton("Display inventory by category"));
    container.add(new JButton("Display all inventory"));
    

    by this (which uses the buttons of your class, on which you then add the listeners):

    container.add(catBtn);
    container.add(allBtn);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which creates an ImageButton and plays a sound when
I have the following code which creates a new table. var html = '<table>';
I have the following code in an external JS file (ie: test.js); which creates
I have following code which works for radio buttons but need to be changed
I have following code which on save from the admin area creates a duplicate
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
I want to know is below code correct ? I have following code which
i have the following code which works fine to download image form url .
I have the following code which is meant to access the local database and
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();

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.