Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

newbie question

Thread view: 
Yumex85 - 15 Feb 2007 10:26 GMT
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","Processamentos","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);

    }

}
Ian Wilson - 15 Feb 2007 10:43 GMT
> Hello,
> Here it is a simple frame i made, with a menubar and several menus I
[quoted text clipped - 3 lines]
> 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",
[quoted text clipped - 4 lines]
>         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.

>         }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.