Help on parameterized constructor please

So i have a menuing system. I create each window in a new class, but the problem is to detect which button is pressed in one of the provider classes by the driver class. I want the driver class to detect i have pressed for instance "list" to run the list class. Here i thought parameterized constructors would work best to get the variables across, but for some reason it is not working. Here is the code: (The gui works and detects the button is pushed etc.)
Provider class:
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.awt.*;
public class MainMenu implements ActionListener
     public String choice = "";
     public MainMenu(String c)
          choice = c;
     JFrame jf = new JFrame("Main Menu");
     Toolkit tk = Toolkit.getDefaultToolkit ();
    int x = (int) tk.getScreenSize ().getWidth ();
    int y = (int) tk.getScreenSize ().getHeight ();
    ImageIcon ev = new ImageIcon("event.png");
    ImageIcon lb = new ImageIcon("list.png");
    ImageIcon cv = new ImageIcon("vote.png");
    ImageIcon bb = new ImageIcon("bio.png");
    Font f1 = new Font ("Tahoma", Font.BOLD, 25);
    Font f2 = new Font ("Chiller", Font.BOLD, 100);
    JLabel lbl = new JLabel("MAIN MENU");
    JLabel space = new JLabel ("");
     JButton jb1 = new JButton("Events", ev);
     JButton jb2 = new JButton("Leader Board", lb);
     JButton jb3 = new JButton("Cast Vote", cv);
     JButton jb4 = new JButton("Band Biographies", bb);
     GridLayout grid = new GridLayout(10,10,1,1);
     JPanel jp0 = new JPanel();
     JPanel jp1 = new JPanel();
     JPanel jp2 = new JPanel();
     JPanel jp3 = new JPanel();
     JPanel jp4 = new JPanel();
     public MainMenu()
         lbl.setFont(f2);
         jf.setBounds(0,0, x,y);
          jf.setVisible(true);
          jf.setResizable(false);
          jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          jb1.addActionListener(this);
          jb2.addActionListener(this);
          jb3.addActionListener(this);
          jb4.addActionListener(this);
          jb1.setFont(f1);
          jb2.setFont(f1);
          jb3.setFont(f1);
          jb4.setFont(f1);
          jp0.add(lbl);
         jp1.add(jb1);
         jp2.add(jb2);
         jp3.add(jb3);
         jp4.add(jb4);
         jf.setLayout(grid);
         jf.add(space);
         jf.add(space);
         jf.add(jp0);
         jf.add(space);
         jf.add(jp1);
         jf.add(jp2);
         jf.add(jp3);
         jf.add(jp4);
         jf.repaint();
    public void actionPerformed (ActionEvent e)
         if (e.getSource () == jb1)
              choice = "events";
              System.out.println(choice);//Just to test whether the buttons work...
         else if (e.getSource () == jb2)
              choice = "list";
              System.out.println(choice);
         else if (e.getSource () == jb3)
              choice = "vote";
              System.out.println(choice);
         else if (e.getSource () == jb4)
              choice = "bio";
              System.out.println(choice);
    public String getChoice()
         return choice;
}and here is the driver class which doesnt read the change in the choice variable:
public class PAT
    public static void main(String[] args) //implements ActionListener
          String choice = "";
          MainMenu mm = new MainMenu(choice);
          new MainMenu();
          while (choice.equals(""))
          if (choice.equals("list"))
               System.out.println("Parameterized constructor works");
}Any help or advice would be greatly appreciated. Thanks in advance.

Here is exactly what im trying to do. Im making a menu system. It consists of several windows. For instance main menu has 3 buttons. each button takes you to a new window. Each new window has a back button to return to the main menu. and then the new windows might also have buttons to go to another new window and will have buttons too.
Im making each window (menu window) in a new class. I want to be able to call these classes (windows) as desired. so all the loops and so on to run the different windows at the right times should be in the main class. makes it easier, as ill be jumping around between programs much less. i just want my parameterized constructors to work, because i believe this will be the easiest way. to have variables, that if changed in one of the provider classes, they will change in the driver class too. this way all i do is change a variable when a button i clicked in the provider classes. then the driver class does a certain action according to the value of the variable read from the provider classes. for instance my choice variable (which is now an int) detects what button is clicked. then my driver class runs the next window based on the value of choice which it recieved from the other classes.
I hope it makes sense.
Thank you for the quick replies.

Similar Messages

  • Parameterized constructor in servlets

    why can't we use parameterized constructor in servlets?
    please describe it briefly?

    Why should you use parametrized constructor with servlet? If you want to pass any parameter then use <init-param> in web.xml. Even if you make parameterized constructor, how it would be invoked? Servlet container creates instance of servlet by invoking common constructor.
    So do you intent to rewrote container to invoke parameterized constructor?
    Please refer servlet documentation for more information on servlets and it would help you.

  • My Mac was updated to Ÿosemite OS and since then the PS5 software doesn't open. I need help on this subject please.

    My Mac was updated to Ÿosemite OS and since then the PS5 software doesn't open. I need help on this subject please.
    They error message I get is "An unexpected and unrecoverable problem has occurred. Photoshop will now exit."
    This only started after I upgraded my OS to Yosemite.

    The upgrade has been know to break Photoshop CS5 installs. An Uninstall/Reinstall may be necessary.

  • If you want to access the PowerShell 3.0 Help in another language please vote for my Connect suggestion!

    All my Windows operating Systems are set to use the UI Culture: German
    With Update-Help or Save-Help you can download PowerShell help in different (any) language by use of the –UICulture parameter.
    Update-Help –UICulture en-US
    Because my Windows OS is set to use the German UI Culture and the Cmdlet Get-Help depends on it, I cannot access PowerShell help in a different Language (English) with Get-Help.
    There is still no translated German PowerShell help and even if I have installed the en-US verbose Help files I cannot use it (easily)!
    I made a suggestion on Microsoft Connect to add the –UICulture Parameter to the Get-Help Cmdlet, to make it possible to call Help in a different language then the Windows Ui Culture.
    As a workaround until then you can use the  .NET Class [System.Threading.Thread]::CurrentThread.CurrentUICulture to set the UI Culture and get Help in a different language.
    Function Get-HelpUICulture {
    param (
    [String]$HelpSearchString,
    [String]$UICulture
    # remember the UICulture
    $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
    trap
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $OldCulture
    # set thread to given UICulture
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $UICulture
    # call powershell help in given language
    Get-Help $HelpSearchString -Full
    # reset UICulture
    [System.Threading.Thread]::CurrentThread.CurrentUICulture = $OldCulture
    # Example: call PowerShell en-US help in verbose English:
    Get-HelpUICulture -HelpSearchString Get-Command -UICulture ‘en-US’
    If you want to access the PowerShell 3.0 Help in another language please vote for my Connect suggestion!
    https://connect.microsoft.com/PowerShell/feedback/details/767899/please-add-uiculture-to-get-help
    Please click “Mark as Answer” if my post answers your question and click
    “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als
    “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!

    Hello JosKW
    Thank you for your suggestions!
    In my 3 Part Blog Series about the new 3.0 PowerShell,  I offer a full blown Proxy Function for the Get-Help cmdlet to solve this better.
    For now I have the first two Articles Published at my Blog, the Third Part will follow soon:
    PowerShell 3.0 updateable help Update-Help, Save-Help und Get-Help Basics
    http://www.admin-source.de/BlogDeu/497/powershell-3-0-updateable-help-update-help-save-help-und-get-help-grundlagen
    PowerShell 3.0 updateable help Update-Help, Save-Help und Get-Help using
    http://www.admin-source.de/BlogDeu/523/powershell-3-0-updateable-help-update-help-save-help-und-get-help-anwenden
    The Articles are written in German. I think you as a Dutchman can read this.
    Or you can use the Translate Button on my Page, to use Google Translate Service to read this in the Language of your choice. ;-))
    Cheers Peter
    Please click “Mark as Answer” if my post answers your question and click
    “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als
    “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!

  • I need a help !!! Please  ,I dropped my iPhone 5 in toilet and I didn't get fast  maybe 5mins before I get it because I didn't notice drop it and it won't work now  it's almost 1week I'm waiting it  still  it don't work ...

    I need a help !!! Please  ,I dropped my iPhone 5 in toilet and I didn't get fast  maybe 5mins before I get it because I didn't notice drop it and it won't work now  it's almost 1week I'm waiting it  still  it don't work ... But when I plug my charger it goes light and show up apple logo and die again I don't know what to do and it's so expensive here at Japan pls.. Help maybe there still way to get it work again
    Thank you ,Rean

    At this point it's clear that it's been damaged and will need to be take or sent to Apple for replacement.
    Regards.

  • Im stuck with this message "no bootable device, insert boot disk and press any key". Now i want to go back to mac os but everytime i turn on my laptop that message appear..kindly help... Please

    Im stuck with this message "no bootable device, insert boot disk and press any key". Now i want to go back to mac os but everytime i turn on my laptop that message appear..kindly help... Please .... Im using my usb as bootable device but it cant be detected..

    Reboot, hold the option key down, select OSX when the startup manager appears.

  • Uloading ebook using iProducer rec'd error: ERROR ITMS-9000: "Unable to parse nav file: toc.ncx" at Book. I don't understand and need help fixing it. Please Help

    Uloading ebook using iProducer rec'd error: ERROR ITMS-9000: "Unable to parse nav file: toc.ncx" at Book. I don't understand and need help fixing it. Please Help if you've the knowledge.
    Many Thanks

    Yep, i just did it again. The entire scroll-bar widget, complete with formatted text, graphics, etc., pasted itself nicely in another book. Two different files, the same widget.
    I use the scroll-bar widgets for most of my texts. (I have audio buttons on the side, and the scripts are within the widget, to the side). My only text is within widgets, and text boxes, naturally. 
    I am following your recommendation: cleaning files, etc. I am remaking the book anew. I need to convince the EPUB bot or whatever that my file looks and works nicely on all my devices. You would expect an error message when previewing the book: 'Hey Amigo, your file is flawed, stop working on it, and get back to the drawing board." Should be able to try again next Monday.

  • My iCloud is disabled. I've reset my password numerous times, but that doesn't help. Can someone please tell me how can I log onto my iCloud

    My iCloud is disabled. I've reset my password numerous times, but that doesn't help. Can someone please tell me how can I log onto my iCloud

    If your ID is disabled, you'll have to contact Apple for assistance, either by going to https://expresslane.apple.com, then click More Produces & Services>Apple ID>iTunes Store, App Store or Mac App Store>Disabled Apple ID, or by contacting the Apple account security team: http://support.apple.com/kb/HT5699.

  • I am trying to buy mitril for hobbit kom but it always gives me error i have already added my card information to store but i cant buy it.Could u help me about it ,please?

    I am trying to buy mitril for hobbit kom but it always gives me error i have already added my card information to store but i cant buy it.Could u help me about it ,please?

    Wish I could help. My wife is having the same problem.  Same computer for 2 years and all of a suddent it thinks this is her first purchase.

  • HT3775 why can't i play .wmv file in quicktime even after i download codec from windows? can anyone help me wit this please!!!!!

    why can't i play .wmv file in quicktime even after i download codec from windows? can anyone help me wit this please!!!!!

    Have you done the obvious things to try to fix it: quit Quicktime then start it back up again, log out then back in, reboot.
    Edit: Just read one of your later posts. If VLC won't play it, this is unrelated to Quicktime and Flip4Mac. Are you sure these wmv files are okay?

  • TS3276 I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    http://support.apple.com/kb/HT5922
    If you want to mirror your desktop, see:
    http://support.apple.com/kb/HT5404
    Regards.

  • TS3276 can anyone help on the following please. When I have been away from the office for a few days and check for emails it only supplies the most recent 100 emails and the ones before that are never received. thanks

    can anyone help on the following please. When I have been away from the office for a few days and check for emails it only supplies the most recent 100 emails and the ones before that are never received. thanks

    Does your server have a limit?

  • I have a brand new MacBookProo and I can not open PDF files from my desktop. Can anyone help me with this please?

    I have a brand new MacBookProo and I can not open PDF files from my desktop. Can anyone help me with this please?

    A new Mac comes with 90 days of free tech support from AppleCare.
    AppleCare: 1-800-275-2273

  • Just for my own privacy i would like to set up a password or pin number on my messgae app is there anything out there that will help me do this please comment if there is a possible solution out there

    Just for my own privacy i would like to set up a password or pin number on my messgae app is there anything out there that will help me do this please comment if there is a possible solution out there. I know alot may say what you have to hide but ive got nothing to hide i just want one on there so my privacy is not broken by friends and family if they fancy playing on my phone and having a snoop round my phone.

    If you visit these forums often, you will read about the 2 year old child who accidentally wiped out the parents phone, the kid who set a passcode and didn't remember what it was, etc etc etc
    Passcode your device.   Protect your device.   It really isn't a toy.    The toy is the iPod touch.

  • What does it mean when Siri keeps saying "I can't help you right now, please come back later."?

    What does it mean when Siri keeps saying, "I can't help you right now, please try again later."?

    Pretty much what it says, SIri can't help you right now.  I suspect it's a location, nework and/or server issue.  Siri is currently Beta and doesn't always work.

Maybe you are looking for