4 Replies - 399 Views - Last Post: 12 May 2012 - 11:13 AM Rate Topic: -----

#1 PleaseHelpne  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 11-May 12

How can I remove the submenus in this program? (picture included)

Posted 12 May 2012 - 10:09 AM

Posted Image
I want to remove Random Player, Defensive Player, Aggressive Player, and MinMax Player. I also want to make "Aggressive Player the type of player chosen when the "Computer" menu is clicked.
Whenever I try to do it, I keep on messing up.
        menu = new JMenu("Players");
        menu.setMnemonic(KeyEvent.VK_P);
        menuBar.add(menu);
        submenu = new JMenu("Player 1");
        ButtonGroup groupPlayers1 = new ButtonGroup();
        rbMenuItem = new JRadioButtonMenuItem("Human");
        if (p1.getType() == 0) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Human");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        submenu.add(rbMenuItem);
        subsubmenu = new JMenu("Computer");
        rbMenuItem = new JRadioButtonMenuItem("Random Player");
        if (p1.getType() == 1) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Random");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("Defensive Player");
        if (p1.getType() == 2) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Defensive");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("Aggressive Player");
        if (p1.getType() == 3) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Aggressive");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("MinMax Player");
        if (p1.getType() == 4) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1MinMax");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        submenu.add(subsubmenu);
        menu.add(submenu);
        submenu = new JMenu("Player 2");
        ButtonGroup groupPlayers2 = new ButtonGroup();
        subsubmenu = new JMenu("Computer");
        rbMenuItem = new JRadioButtonMenuItem("Random Player");
        if (p2.getType() == 1) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P2Random");
        rbMenuItem.addItemListener(this);
        groupPlayers2.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("Defensive Player");
        if (p2.getType() == 2) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P2Defensive");
        rbMenuItem.addItemListener(this);
        groupPlayers2.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("Aggressive Player");
        if (p2.getType() == 3) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P2Aggressive");
        rbMenuItem.addItemListener(this);
        groupPlayers2.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("MinMax Player");
        if (p2.getType() == 4) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P2MinMax");
        rbMenuItem.addItemListener(this);
        groupPlayers2.add(rbMenuItem);
        subsubmenu.add(rbMenuItem);
        submenu.add(subsubmenu);
        rbMenuItem = new JRadioButtonMenuItem("Human");
        if (p1.getType() == 0) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P2Human");
        rbMenuItem.setSelected(true);
        rbMenuItem.setMnemonic(KeyEvent.VK_H);
        groupPlayers2.add(rbMenuItem);
        rbMenuItem.addItemListener(this);
        submenu.add(rbMenuItem);
        menu.add(submenu);



Is This A Good Question/Topic? 0
  • +

Replies To: How can I remove the submenus in this program? (picture included)

#2 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 48
  • View blog
  • Posts: 250
  • Joined: 02-February 09

Re: How can I remove the submenus in this program? (picture included)

Posted 12 May 2012 - 10:15 AM

what happens if you remove this line?

groupPlayers1.add(rbMenuItem);
Was This Post Helpful? 1
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,653
  • Joined: 02-June 10

Re: How can I remove the submenus in this program? (picture included)

Posted 12 May 2012 - 10:19 AM

I'm confused as to why this is causing you grief. You can see where they are created starting at line 12.

Comment out the lines that make them.

You could let them be created and just not add them.
See in line 35 where they are added to the groupPlayer1?
Comment out that line: 35

I'm guessing you didn't make this code. Do you have no understanding of any of this; its all gibberish to you? You're dismantling someone else's code in an effort to learn java?

There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2.
Sure, 35 years ago the only way I could learn BASIC as a kid was to type programs from a book into a TRS-80 model 1 or Commodore VIC-20, then figure out the commands and syntax by watching the results as the program ran. There simply wasn't any courses for a kid back then.

But now, you can't help but to trip over "Learn {coding language} in 3 weeks" type books and the entire internet is at your disposal for tutorials.

I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 0
  • +
  • -

#4 PleaseHelpne  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 11-May 12

Re: How can I remove the submenus in this program? (picture included)

Posted 12 May 2012 - 10:40 AM

View Postoha055, on 12 May 2012 - 10:15 AM, said:

what happens if you remove this line?

groupPlayers1.add(rbMenuItem);


Posted Image
I did that and some more, but now Computer doesn't show up. What did I do wrong?

  menu = new JMenu("Players");
        menu.setMnemonic(KeyEvent.VK_P);
        menuBar.add(menu);
        submenu = new JMenu("Player 1");
        ButtonGroup groupPlayers1 = new ButtonGroup();
        rbMenuItem = new JRadioButtonMenuItem("Human");
        if (p1.getType() == 0) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Human");
        rbMenuItem.addItemListener(this);
        groupPlayers1.add(rbMenuItem);
        submenu.add(rbMenuItem);
        rbMenuItem = new JRadioButtonMenuItem("Computer");
        //if (p1.getType() == 1) rbMenuItem.setSelected(true);
        //rbMenuItem.setName("P1Random");
       // rbMenuItem.addItemListener(this);
        //groupPlayers1.add(rbMenuItem);
       // subsubmenu.add(rbMenuItem);
       // rbMenuItem = new JRadioButtonMenuItem("Defensive Player");
        //if (p1.getType() == 2) rbMenuItem.setSelected(true);
       // rbMenuItem.setName("P1Defensive");
       // rbMenuItem.addItemListener(this);
       // groupPlayers1.add(rbMenuItem);
       // subsubmenu.add(rbMenuItem);
       // rbMenuItem = new JRadioButtonMenuItem("Aggressive Player");
        if (p1.getType() == 3) rbMenuItem.setSelected(true);
        rbMenuItem.setName("P1Aggressive");
        rbMenuItem.addItemListener(this);
       // groupPlayers1.add(rbMenuItem);
        //subsubmenu.add(rbMenuItem);
        //rbMenuItem = new JRadioButtonMenuItem("MinMax Player");
        //if (p1.getType() == 4) rbMenuItem.setSelected(true);
        //rbMenuItem.setName("P1MinMax");
       // rbMenuItem.addItemListener(this);
       // groupPlayers1.add(rbMenuItem);
       // subsubmenu.add(rbMenuItem);
       // submenu.add(subsubmenu);


View PosttlhIn`toq, on 12 May 2012 - 10:19 AM, said:

I'm confused as to why this is causing you grief. You can see where they are created starting at line 12.

Comment out the lines that make them.

You could let them be created and just not add them.
See in line 35 where they are added to the groupPlayer1?
Comment out that line: 35

I'm guessing you didn't make this code. Do you have no understanding of any of this; its all gibberish to you? You're dismantling someone else's code in an effort to learn java?

There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2.
Sure, 35 years ago the only way I could learn BASIC as a kid was to type programs from a book into a TRS-80 model 1 or Commodore VIC-20, then figure out the commands and syntax by watching the results as the program ran. There simply wasn't any courses for a kid back then.

But now, you can't help but to trip over "Learn {coding language} in 3 weeks" type books and the entire internet is at your disposal for tutorials.

I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler



I agree with you! However, the truth is I learn far better when I analyze other programmer's code! I get to delete and add code, and see how it works myself. It gets deep into my mind because I can connect it to other things I know, other than just being spoon fed instructions.
Was This Post Helpful? 0
  • +
  • -

#5 PleaseHelpne  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 8
  • Joined: 11-May 12

Re: How can I remove the submenus in this program? (picture included)

Posted 12 May 2012 - 11:13 AM

Alright! Nevermind everyone, I figured it out. Thanks so much for your tips, though!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1