Results 1 to 2 of 2
  1. #1
    skatefreak is offline Member
    Join Date
    Jan 2009
    Posts
    18
    Rep Power
    0

    Thumbs down panes, frames and ddm's :|

    Hey,
    So here is something i put together a long time ago, i'm sure a few may recognise some of the code being from java sun no doubt.

    A little background, basically having been into R/C modeling heavily for many years in the past (R/C helis) and having a million different bits here and there I figured a program to keep track of all the bits would be a fun project.
    Quiet simply everything would be inputted into an sql database (still have to make that bit) and then it can be displayed and browsed via this browser thing i'm trying to put together!

    My main question is how would i get this window to bring up an interface relevant to the selection from the drop down menu, within the empty frame below the menu?

    My thinking is an action listener would catch the selection which would then alter a variable which would determine the table in sql data would be brought up from but how, and here's were i need some direction, would i get the user interface to pop up?
    There are only likely to be a few different configurations to display the information (4-6) so i would only need a few different windows to bring up, eveything else would be dependant on the data brought up.

    Java Code:
    package Program;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JRadioButtonMenuItem;
    import javax.swing.ButtonGroup;
    import javax.swing.JMenuBar;
    import javax.swing.KeyStroke;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    
    
    
    public class main
    {
        static String where;
        JTextArea output;
        JScrollPane scrollPane;
    
        
        public JMenuBar createMenuBar() {
            JMenuBar menuBar;
            JMenu menu, submenu;
            JMenuItem menuItem;
            JRadioButtonMenuItem rbMenuItem;
            JCheckBoxMenuItem cbMenuItem;
    
            //Create the menu bar.
            menuBar = new JMenuBar();
    
            //Build the first menu.
            menu = new JMenu("Airframes");
            menu.setMnemonic(KeyEvent.VK_A);
    
            menuBar.add(menu);
            
            //a group of JMenuItems
            menuItem = new JMenuItem("Helicopters");
            menu.add(menuItem);
            
            menuItem = new JMenuItem("Aeroplanes");
            menu.add(menuItem);
            //Build second menu in the menu bar.
            menu = new JMenu("Engines");
            menuBar.add(menu);
            //a group of JMenuItems
            menuItem = new JMenuItem("Helicopters");
            menu.add(menuItem);
            
            menuItem = new JMenuItem("Aeroplanes");
            menu.add(menuItem);
            
            //Build second menu in the menu bar.
            menu = new JMenu("Electronics");
            menuBar.add(menu);
            //a group of JMenuItems
            menuItem = new JMenuItem("Recivers");
            menu.add(menuItem);
            
            menuItem = new JMenuItem("Servos");
            menu.add(menuItem);
                    
            menuItem = new JMenuItem("Gyros");
            menu.add(menuItem);
                    
            menuItem = new JMenuItem("Govners");
            menu.add(menuItem);
                    
            menuItem = new JMenuItem("Misc");
            menu.add(menuItem);
            
            
            return menuBar;
        }
    
        public Container createContentPane() {
            //Create the content-pane-to-be.
            JPanel contentPane = new JPanel(new BorderLayout());
            contentPane.setOpaque(true);
    
            //Create a scrolled text area.
            output = new JTextArea(5, 30);
            output.setEditable(false);
            scrollPane = new JScrollPane(output);
    
            //Add the text area to the content pane.
            contentPane.add(scrollPane, BorderLayout.CENTER);
    
            return contentPane;
        }
    
    
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        static void createAndShowGUI() {
            //Create and set up the window.
            where = location.where;
            JFrame frame = new JFrame("Thingys in " + where);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            //Create and set up the content pane.
            main myMain = new main();
            frame.setJMenuBar(myMain.createMenuBar());
            frame.setContentPane(myMain.createContentPane());
    
            //Display the window.
            frame.setSize(450, 260);
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    
    }
    Any thoughts, criticism, advice and guidence would be much appreciated :)

    Best regards

    -Chris Jvr

  2. #2
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default

    What was your question exactly? Something about adding something to which depending on what? Huh?

    ... and... good code is succinct ;-)

    Java Code:
    package forums;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ChrisSkateFreaksRemoteControlControler
    {
      private static JMenu createMenu(String name, String... items) {
        JMenu menu = new JMenu(name);
        for ( String item : items ) {
          menu.add(new JMenuItem(item));
        }
        return menu;
      }
    
      private static JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(createMenu("Airframes", "Helicopters", "Aeroplanes"));
        menuBar.add(createMenu("Engines", "Helicopters", "Aeroplanes"));
        menuBar.add(createMenu("Electronics", "Recievers", "Servos", "Gyros", "Governors", "Miscellaneous"));
        return menuBar;
      }
    
      private static Container createContentPane() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setOpaque(true);
        JTextArea output = new JTextArea(23, 80);
        output.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(output);
        panel.add(scrollPane, BorderLayout.CENTER);
        return panel;
      }
    
      private static void createAndShowGUI() {
        JFrame frame = new JFrame("Chris Skatefreaks RemoteControl Controler!!!");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ChrisSkateFreaksRemoteControlControler me = new ChrisSkateFreaksRemoteControlControler();
        frame.setJMenuBar(me.createMenuBar());
        frame.setContentPane(me.createContentPane());
        frame.pack();
        frame.setVisible(true);
      }
    
      public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            createAndShowGUI();
          }
        });
      }
    }
    Cheers. Keith.

Similar Threads

  1. navigation b/w frames
    By imrankhan in forum AWT / Swing
    Replies: 3
    Last Post: 03-19-2012, 12:25 PM
  2. GUI Help(Layered panes, opacity, events)
    By xcallmejudasx in forum New To Java
    Replies: 1
    Last Post: 04-29-2009, 11:11 PM
  3. Help regarding Frames
    By ramesh.8189 in forum AWT / Swing
    Replies: 14
    Last Post: 02-15-2009, 08:12 AM
  4. Grid layout frames GUI
    By fritz1474 in forum AWT / Swing
    Replies: 1
    Last Post: 10-15-2008, 02:04 AM
  5. Two content panes in one GUI?
    By Leprechaun in forum New To Java
    Replies: 1
    Last Post: 01-31-2008, 04:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •