Advertisement
Guest User

NetBeans GUI, other layouts

a guest
Sep 19th, 2010
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package temp;
  2.  
  3. import java.awt.Color;
  4. import java.util.Random;
  5.  
  6. public class Main extends javax.swing.JFrame {
  7.  
  8.     /** Creates new form NewJFrame */
  9.     public Main() {
  10.         initComponents();
  11.     }
  12.  
  13.     /**
  14.      * This method is called from within the constructor to
  15.      * initialize the form. WARNING: Do NOT modify this code.
  16.      * The content is always regenerated by the Form Editor.
  17.      */
  18.     @SuppressWarnings("unchecked")
  19.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  20.     private void initComponents() {
  21.  
  22.         colorPanel = new javax.swing.JPanel();
  23.         buttonPanel = new javax.swing.JPanel();
  24.         changeButton = new javax.swing.JButton();
  25.  
  26.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  27.         setBackground(new java.awt.Color(0, 255, 255));
  28.         getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(),
  29.             javax.swing.BoxLayout.PAGE_AXIS));
  30.  
  31.         colorPanel.setBackground(new java.awt.Color(255, 0, 255));
  32.         colorPanel.setPreferredSize(new java.awt.Dimension(320, 240));
  33.         getContentPane().add(colorPanel);
  34.  
  35.         buttonPanel.setBackground(new java.awt.Color(0, 255, 255));
  36.         buttonPanel.setPreferredSize(new java.awt.Dimension(320, 120));
  37.         buttonPanel.setLayout(new java.awt.GridBagLayout());
  38.  
  39.         changeButton.setText("Change Colors");
  40.         changeButton.addActionListener(new java.awt.event.ActionListener() {
  41.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  42.                 changeButtonActionPerformed(evt);
  43.             }
  44.         });
  45.         buttonPanel.add(changeButton, new java.awt.GridBagConstraints());
  46.  
  47.         getContentPane().add(buttonPanel);
  48.  
  49.         pack();
  50.     }// </editor-fold>
  51.  
  52.     private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                      
  53.         colorPanel.setBackground(new Color(r.nextInt()));
  54.         buttonPanel.setBackground(new Color(r.nextInt()));
  55.     }                                      
  56.  
  57.     /**
  58.     * @param args the command line arguments
  59.     */
  60.     public static void main(String args[]) {
  61.         java.awt.EventQueue.invokeLater(new Runnable() {
  62.             public void run() {
  63.                 new Main().setVisible(true);
  64.             }
  65.         });
  66.     }
  67.  
  68.     private static final Random r = new Random();
  69.     // Variables declaration - do not modify
  70.     private javax.swing.JPanel buttonPanel;
  71.     private javax.swing.JButton changeButton;
  72.     private javax.swing.JPanel colorPanel;
  73.     // End of variables declaration
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement