Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package main;
- import java.awt.Color;
- /**
- *
- * @author sao_7
- */
- public class Menu extends javax.swing.JFrame {
- /**
- * Creates new form Menu
- */
- private boolean stateBtnRed = true;
- private boolean stateBtnGreen = true;
- private boolean stateBtnBlue = true;
- private boolean stateBtnMixed = true;
- public Menu() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- btnRed = new javax.swing.JButton();
- btnGreen = new javax.swing.JButton();
- btnBlue = new javax.swing.JButton();
- btnMixed = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- btnRed.setBackground(new java.awt.Color(102, 153, 255));
- btnRed.setText("Sarkans");
- btnRed.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnRedActionPerformed(evt);
- }
- });
- btnGreen.setBackground(new java.awt.Color(102, 204, 255));
- btnGreen.setText("Zaļš");
- btnGreen.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnGreenActionPerformed(evt);
- }
- });
- btnBlue.setBackground(new java.awt.Color(102, 204, 255));
- btnBlue.setText("Zils");
- btnBlue.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnBlueActionPerformed(evt);
- }
- });
- btnMixed.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnMixedActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(31, 31, 31)
- .addComponent(btnRed, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(33, 33, 33)
- .addComponent(btnGreen, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnBlue, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(54, 54, 54)
- .addComponent(btnMixed, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(82, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(33, 33, 33)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnRed, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnGreen, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnBlue, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(47, 47, 47)
- .addComponent(btnMixed, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(70, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void btnRedActionPerformed(java.awt.event.ActionEvent evt) {
- if (stateBtnRed) {
- btnRed.setBackground(Color.red);
- btnRed.setForeground(Color.white);
- } else {
- btnRed.setBackground(Color.gray);
- btnRed.setForeground(Color.black);
- }
- if (stateBtnRed && stateBtnGreen) {
- btnMixed.setBackground(Color.yellow);
- }
- stateBtnRed = !stateBtnRed;
- mixBtnStateChange();
- }
- private void btnGreenActionPerformed(java.awt.event.ActionEvent evt) {
- if (stateBtnGreen) {
- btnGreen.setBackground(Color.green);
- btnGreen.setForeground(Color.white);
- // if (!stateBtnRed && !stateBtnGreen) {
- // btnMixed.setBackground(Color.yellow);
- // }
- } else {
- btnGreen.setBackground(Color.gray);
- btnGreen.setForeground(Color.black);
- }
- stateBtnGreen = !stateBtnGreen;
- mixBtnStateChange();
- }
- private void btnBlueActionPerformed(java.awt.event.ActionEvent evt) {
- if (stateBtnBlue) {
- btnBlue.setBackground(Color.blue);
- btnBlue.setForeground(Color.white);
- } else {
- btnBlue.setBackground(Color.gray);
- btnBlue.setForeground(Color.black);
- }
- stateBtnBlue = !stateBtnBlue;
- mixBtnStateChange();
- }
- private void btnMixedActionPerformed(java.awt.event.ActionEvent evt) {
- btnRed.setBackground(Color.gray);
- stateBtnRed = false;
- btnGreen.setBackground(Color.gray);
- stateBtnGreen = false;
- btnBlue.setBackground(Color.gray);
- stateBtnBlue = false;
- btnMixed.setBackground(Color.gray);
- }
- private void mixBtnStateChange(){
- if (!stateBtnGreen && !stateBtnRed && stateBtnBlue) {
- btnMixed.setBackground(Color.yellow);
- }
- if (!stateBtnGreen && !stateBtnBlue && stateBtnRed) {
- btnMixed.setBackground(Color.cyan);
- }
- if (!stateBtnRed && !stateBtnBlue && stateBtnGreen) {
- btnMixed.setBackground(Color.magenta);
- }
- if (!stateBtnRed && !stateBtnGreen && !stateBtnBlue) {
- btnMixed.setBackground(Color.white);
- }
- if (stateBtnRed && stateBtnGreen && stateBtnBlue) {
- btnMixed.setBackground(Color.gray);
- }
- if (stateBtnGreen && stateBtnRed && !stateBtnBlue) {
- btnMixed.setBackground(Color.blue);
- }
- if (stateBtnGreen && !stateBtnRed && stateBtnBlue) {
- btnMixed.setBackground(Color.red);
- }
- if (!stateBtnGreen && stateBtnRed && stateBtnBlue) {
- btnMixed.setBackground(Color.green);
- }
- differentMixedStateChange();
- }
- private void differentMixedStateChange(){
- String result = String.valueOf(stateBtnRed) + String.valueOf(stateBtnGreen)
- + String.valueOf(stateBtnBlue);
- switch(result){
- case "truefalsefalse":
- btnMixed.setBackground(Color.red);
- break;
- case "falsetruefalse":
- btnMixed.setBackground(Color.green);
- break;
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Menu().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnBlue;
- private javax.swing.JButton btnGreen;
- private javax.swing.JButton btnMixed;
- private javax.swing.JButton btnRed;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement