Results 1 to 4 of 4
  1. #1
    nik_meback is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Overall strutcure of Swing app

    Before I actually begin coding my Swing app, I need to know what structure would be appropriate. I have a rough idea of what my app needs to look like conceptually and would like you to review the structure and suggest any changes if needed. Plz overlook the length of my code. It's rather long, I admit.

    Java Code:
    public class MyApp {
    	JMenuBar myMenuBar = null;
    	JToolBar myToolBar = null;
    	JMenuItem myMenuItem1 = null;
    	JMenuItem myMenuItem2 = null;
    	JPanel northPanel = null;
    	JPanel westPanel = null;
    	JPanel centerPanel = null;
    	JPanel eastPanel = null;	
    	JPanel southPanel = null;
    	
    	public JPanel createNorthPanel() {
    		northPanel = new JPanel();		
    		northPanel.add(createMenuBar());
    		northPanel.add(createToolBar());
    		return northPanel;
    	}
    	
    	// similarly, create 'west', 'center', 'east' and 'south' panels
    	
    	// I need this method because my menu bar has quite a few menu items
    	public JMenuItem createMenuItem(String text, char mnemonic, String keyStrokeRepresentation) {
    		JMenuItem newMenuItem = new JMenuItem();
    		// set respective properties...		
    		return newMenuItem;
    	}		
    		
    	public JMenuBar createMenuBar() {
    		myMenuBar = new JMenuBar();
    		
    		myMenuBar.add(myMenuItem1 = createMenuItem("MyMenuItem1", 'M', "control M"));	
    		myMenuItem1.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent actionEvent) {
    				// take some action here...
    			}
    		}	
    		
    		// similarly, create other menu items
    		
    		return myMenuBar;
        }
    	
        public JToolBar createToolBar() {
    		// similarly, create toolbar
        }
    	
    	public static void main(String args[]) {
    		// implementing thread safety...
    		Runnable runner = new Runnable() {
    			public void run() {
    				JFrame mainFrame = new JFrame();				
    				MyApp appInstance = new MyApp();
    				
    				mainFrame.add(appInstance.createNorthPanel(), BorderLayout.NORTH);
    				
    				// similarly, create 'west', 'center', east' and 'south' panels...
    				mainFrame.add(appInstance.createWestPanel(), BorderLayout.WEST);
    				mainFrame.add(appInstance.createCenterPanel(), BorderLayout.CENTER);				
    				mainFrame.add(appInstance.createEastPanel(), BorderLayout.EAST);				
    				mainFrame.add(appInstance.createSouthPanel(), BorderLayout.SOUTH);	
    				
    				mainFrame.setVisible(true);
    				mainFrame.setSize(400, 300);
    			}
    		};
    		
    		EventQueue.invokeLater(runner);
    	}
    }
    Last edited by Fubarable; 12-03-2010 at 06:17 PM. Reason: Moderator Edit: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    nik_meback is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Moderation Actions:
    1) code tags added
    2) abusive post deleted.
    Was my post abusive in any way? Yes, I agree the code I mentioned was a bit lengthy, but all I wanted to ask was whether my GUI design was correct or not.
    The reason I supplied a lengthy code was that it would save me asking multiple questions in different threads.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by nik_meback View Post
    Was my post abusive in any way? Yes, I agree the code I mentioned was a bit lengthy, but all I wanted to ask was whether my GUI design was correct or not.
    No, not at all. It wasn't your post I deleted. I did add code tags to it though.

    The reason I supplied a lengthy code was that it would save me asking multiple questions in different threads.
    You'll want to learn how to use code tags next time so that your code will retain its formatting, that's all.

Similar Threads

  1. swing
    By mnatalka in forum New To Java
    Replies: 5
    Last Post: 12-03-2008, 08:26 AM
  2. AWT or Swing
    By bugger in forum AWT / Swing
    Replies: 4
    Last Post: 11-22-2007, 10:44 AM
  3. where is the swing jar?
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:58 PM
  4. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM
  5. swing?? why use it
    By javaforme44a in forum AWT / Swing
    Replies: 3
    Last Post: 07-18-2007, 08:51 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
  •