Advertisement
Guest User

Main.java

a guest
Oct 26th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. package com.androcode.LDB;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. import javax.swing.*;
  7.  
  8. import java.util.logging.*;
  9.  
  10. public class Main {
  11.  
  12. // Component prototypes:
  13. // Labels:
  14. JLabel mainMenuLabel;
  15.  
  16. // Buttons:
  17. JButton addLanternButton;
  18. JButton findLanternButton;
  19. JButton viewAllButton;
  20. JButton exitButton;
  21.  
  22. // Panels:
  23. JPanel setPanel;
  24. JPanel aLPanel;
  25.  
  26. // Main Frame function:
  27. public Main() {
  28. initComponents();
  29. }
  30.  
  31. // Component initiation function:
  32. public void initComponents() {
  33. // Constraint variable for the GridBag Layout:
  34. GridBagConstraints constraints;
  35.  
  36. // Main JFrame:
  37. JFrame mainFrame = new JFrame( "Lighting DB" );
  38. mainFrame.setPreferredSize ( new Dimension ( 500, 400 ) );
  39. mainFrame.getContentPane().setLayout ( new GridBagLayout() );
  40.  
  41. // Frame and Component information:
  42. // Labels:
  43. mainMenuLabel = new JLabel ( "Main Menu" );
  44. mainFrame.getContentPane().add ( mainMenuLabel, new GridBagConstraints() );
  45.  
  46. // Buttons:
  47. addLanternButton = new JButton ( "Add Lantern" );
  48. addLanternButton.setMnemonic ( 'A' );
  49. addLanternButton.setPreferredSize ( new Dimension ( 120, 25 ) );
  50. constraints = new GridBagConstraints();
  51. constraints.gridx = 0;
  52. constraints.gridy = 1;
  53. mainFrame.getContentPane().add ( addLanternButton, constraints );
  54.  
  55. findLanternButton = new JButton ( "Find Lantern(s)" );
  56. findLanternButton.setMnemonic ( 'F' );
  57. findLanternButton.setPreferredSize ( new Dimension ( 120, 25 ) );
  58. constraints = new GridBagConstraints();
  59. constraints.gridx = 0;
  60. constraints.gridy = 2;
  61. mainFrame.getContentPane().add ( findLanternButton, constraints );
  62.  
  63. viewAllButton = new JButton ( "View All" );
  64. viewAllButton.setMnemonic ( 'V' );
  65. viewAllButton.setPreferredSize ( new Dimension ( 120, 25 ) );
  66. constraints = new GridBagConstraints();
  67. constraints.gridx = 0;
  68. constraints.gridy = 3;
  69. mainFrame.getContentPane().add ( viewAllButton, constraints );
  70.  
  71. exitButton = new JButton ( "Exit" );
  72. exitButton.setMnemonic ( 'E' );
  73. exitButton.setPreferredSize ( new Dimension ( 80, 25 ) );
  74. constraints = new GridBagConstraints();
  75. constraints.gridx = 0;
  76. constraints.gridy = 10;
  77. constraints.anchor = GridBagConstraints.NORTHWEST;
  78. mainFrame.getContentPane().add ( exitButton, constraints );
  79.  
  80. // Panels:
  81. setPanel = new JPanel();
  82. setPanel.setLayout ( new GridBagLayout() );
  83. constraints = new GridBagConstraints();
  84. constraints.gridx = 2;
  85. constraints.gridy = 0;
  86. constraints.gridwidth = 11;
  87. constraints.gridheight = 10;
  88. constraints.weightx = 1.0;
  89. constraints.weighty = 1.0;
  90. mainFrame.getContentPane().add ( setPanel, constraints );
  91.  
  92. aLPanel = new JPanel();
  93. aLPanel.setLayout ( new GridBagLayout() );
  94. //aLPanel.add ( new addLanternPanel() ); // TODO - When addLanternPanel() is created, remove comments
  95. setPanel.add ( aLPanel, new GridBagConstraints() );
  96.  
  97. mainFrame.pack();
  98.  
  99. // Button ActionListeners:
  100. addLanternButton.addActionListener ( new ActionListener() {
  101. public void actionPerformed ( ActionEvent e ) {
  102. // TODO - add an albActionPerformed() here when created
  103. }
  104. } );
  105.  
  106. findLanternButton.addActionListener ( new ActionListener() {
  107. public void actionPerformed ( ActionEvent e ) {
  108. // TODO - add an flbActionPerformed() here when created
  109. }
  110. } );
  111.  
  112. viewAllButton.addActionListener ( new ActionListener() {
  113. public void actionPerformed ( ActionEvent e ) {
  114. // TODO - add an vabActionPerformed() here when created
  115. }
  116. } );
  117.  
  118. exitButton.addActionListener ( new ActionListener() {
  119. public void actionPerformed ( ActionEvent e ) {
  120. ebActionPerformed ( e );
  121. }
  122. } );
  123.  
  124. }
  125.  
  126. // TODO - Button ActionPerformed functions ONLY ADD WHEN NEEDED to prevent confusion:
  127. private void ebActionPerformed ( ActionEvent e ) {
  128. System.exit ( 0 );
  129. }
  130.  
  131.  
  132.  
  133. public static void main ( String args[] ) {
  134. EventQueue.invokeLater ( new Runnable() {
  135. public void run() {
  136. new Main().setVisible ( true );
  137. }
  138. } );
  139. }
  140.  
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement