Results 1 to 4 of 4
Thread: Overall strutcure of Swing app
- 12-03-2010, 02:40 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 19
- Rep Power
- 0
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 05:17 PM. Reason: Moderator Edit: code tags added
-
Moderation Actions:
1) code tags added
2) abusive post deleted.
- 12-05-2010, 10:16 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 19
- Rep Power
- 0
-
No, not at all. It wasn't your post I deleted. I did add code tags to it though.
You'll want to learn how to use code tags next time so that your code will retain its formatting, that's all.The reason I supplied a lengthy code was that it would save me asking multiple questions in different threads.
Similar Threads
-
swing
By mnatalka in forum New To JavaReplies: 5Last Post: 12-03-2008, 07:26 AM -
AWT or Swing
By bugger in forum AWT / SwingReplies: 4Last Post: 11-22-2007, 09:44 AM -
where is the swing jar?
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:58 PM -
map javax.swing.text.Element to javax.swing.text.View
By elizabeth in forum New To JavaReplies: 1Last Post: 07-30-2007, 07:02 PM -
swing?? why use it
By javaforme44a in forum AWT / SwingReplies: 3Last Post: 07-18-2007, 07:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks