Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > newbie question

Reply
Thread Tools

newbie question

 
 
Yumex85
Guest
Posts: n/a
 
      02-15-2007
Hello,
Here it is a simple frame i made, with a menubar and several menus I
added to menubar. Now I wanna add sub items to each menu. As you can
see below, to add to menus, i made a loop, but now i dont know how i
could add the sub items in each menu, coz i dont know the name of each
object i created . do They all have "menu" name? Are they
automatically kept in an array?

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;


public class ABNAplic {

JFrame mainFrame;
JPanel mainPanel;
String[] menuLista =
{"Cadastros","Consultas","Relatórios","Processamen tos","Reconciliações","Logs
e Consistências","Sobre","Sair"};


public static void main(String[] args) {

ABNAplic mainGui = new ABNAplic();
mainGui.go();

}



public void go() {


mainFrame = new JFrame("Gestão de Operações Financeiras Banco Real
ABN Amro");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);

JMenuBar menuBar = new JMenuBar();


for(String menus:menuLista) {

JMenu menu = new JMenu(menus);
menuBar.add(menu);

}


mainFrame.setJMenuBar(menuBar);
mainFrame.setSize(700,700);
mainFrame.setVisible(true);


}


}

 
Reply With Quote
 
 
 
 
Ian Wilson
Guest
Posts: n/a
 
      02-15-2007
Yumex85 wrote:
> Hello,
> Here it is a simple frame i made, with a menubar and several menus I
> added to menubar. Now I wanna add sub items to each menu. As you can
> see below, to add to menus, i made a loop, but now i dont know how i
> could add the sub items in each menu, coz i dont know the name of each
> object i created . do They all have "menu" name? Are they
> automatically kept in an array?


No, you should create your own structure for keeping track of them, this
could be an array but some other structure such as a hashmap keyed by
menu title might be more useful.

> String[] menuLista = { "Cadastros","Consultas","Relatórios",
> "Processamentos","Reconciliações","Logse Consistências",
> "Sobre","Sair"};
>
> public static void main(String[] args) {
>
> ABNAplic mainGui = new ABNAplic();
> mainGui.go();


It is normal to use a ABNAplic() constructor instead of your go() method.

> }
> public void go() {

ABNAplic() {

<snippage>

> for(String menus:menuLista) {
> JMenu menu = new JMenu(menus);
> menuBar.add(menu);


At this point you can add menu to an array or HashMap or other structure.

> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments