Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package temp;
- import java.awt.Color;
- import java.util.Random;
- public class Main extends javax.swing.JFrame {
- /** Creates new form NewJFrame */
- public Main() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to
- * initialize the form. WARNING: Do NOT modify this code.
- * The content is always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- colorPanel = new javax.swing.JPanel();
- buttonPanel = new javax.swing.JPanel();
- changeButton = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setBackground(new java.awt.Color(0, 255, 255));
- getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(),
- javax.swing.BoxLayout.PAGE_AXIS));
- colorPanel.setBackground(new java.awt.Color(255, 0, 255));
- colorPanel.setPreferredSize(new java.awt.Dimension(320, 240));
- getContentPane().add(colorPanel);
- buttonPanel.setBackground(new java.awt.Color(0, 255, 255));
- buttonPanel.setPreferredSize(new java.awt.Dimension(320, 120));
- buttonPanel.setLayout(new java.awt.GridBagLayout());
- changeButton.setText("Change Colors");
- changeButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- changeButtonActionPerformed(evt);
- }
- });
- buttonPanel.add(changeButton, new java.awt.GridBagConstraints());
- getContentPane().add(buttonPanel);
- pack();
- }// </editor-fold>
- private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {
- colorPanel.setBackground(new Color(r.nextInt()));
- buttonPanel.setBackground(new Color(r.nextInt()));
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Main().setVisible(true);
- }
- });
- }
- private static final Random r = new Random();
- // Variables declaration - do not modify
- private javax.swing.JPanel buttonPanel;
- private javax.swing.JButton changeButton;
- private javax.swing.JPanel colorPanel;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement