newbie question

Discussion in 'Java' started by Yumex85, Feb 15, 2007.

  1. Yumex85

    Yumex85 Guest

    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);


    }


    }
     
    Yumex85, Feb 15, 2007
    #1
    1. Advertising

  2. Yumex85

    Ian Wilson Guest

    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.

    > }
     
    Ian Wilson, Feb 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry C.
    Replies:
    8
    Views:
    263
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    157
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    137
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    126
  5. Miki Tebeka
    Replies:
    0
    Views:
    91
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page