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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:10:15+00:00 2026-05-22T18:10:15+00:00

import javax.swing.*; import java.awt.*; import java.awt.event.*; class Menu extends JFrame implements ActionListener{ // Create

  • 0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Menu extends JFrame implements ActionListener{    

    // Create the components and global variables
    JButton newGameButton = new JButton("New Game");
    JButton instructionGameButton = new JButton("Instructions");
    JButton exitButton = new JButton("Exit");
    JLabel mylabel = new JLabel("Welcome to Blackjack");

    public Menu()
    {

        // Create the window
        super("ThreeButtons");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);

        //Creating the container for the components and set the layout
        Container content = getContentPane();
        FlowLayout layout = new FlowLayout();
        content.setLayout(layout);

        //Adding the event listener
        newGameButton.addActionListener(this);
        instructionGameButton.addActionListener(this);
        exitButton.addActionListener(this);

        //Adding of components
        content.add(mylabel);
        content.add(newGameButton);
        content.add(instructionGameButton);
        content.add(exitButton);


        setContentPane(content);

    }

    //Add the event handler
    public void actionPerformed(ActionEvent event)
    {
    if (event.getActionCommand()=="New Game")
    new lol4();

    if (event.getActionCommand()=="Instructions")
    //new Instructions();

    if (event.getActionCommand()=="Quit ?")
    System.exit(0);


    }


    public static void main (String[] args)
    {
        //Create an instance of my class
    new Menu();
    }

}

Exit does not seem to work

  • 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-22T18:10:16+00:00Added an answer on May 22, 2026 at 6:10 pm

    I never liked the “switch-board” action listeners where the listener tries to do everything and risks doing nothing due to hard to fix bugs. Better I think to use anonymous inner classes either to hold simple code themselves, or if more complex to route code to other methods, or if still more complex, to call a Controller’s method.

    For example:

      newGameButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            newGameActionPerformed(); // delegate this to a class method
         }
      });
    
      instructionGameButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            // call a controller object's methods
            if (myController != null) {
               myController.instructionGameAction();
            }
         }
      });
    
      exitButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            Menu.this.dispose(); // simple code can be called in-line
         }
      });
    

    and elsewhere in the class:

       private void newGameActionPerformed() {
          // TODO add some code here!
       }
    
       public void setController(MyController myController) {
          this.myController = myController;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class tictac2 implements ActionListener{ static
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Stuff extends Applet implements
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class File { private JFrame frame1; private
import java.awt.event.*; import javax.swing.*; public class PlannerMain { JFrame frame; JButton makeMap; JPanel panel;
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.lang.Thread; public class Lthread extends JPanel{ private
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFrame;
import java.awt.*; import javax.swing.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.border.*; public class ChangeButtonShape {
import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton;
This is called GoHomeAction.java import javax.swing.*; import java.awt.Image; import java.awt.event.ActionEvent; import static java.awt.event.KeyEvent.VK_H; public
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.*; import java.lang.String;

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.