/* * NeuronDemo01.java * * Created on January 24, 2005, 8:05 AM */ package cs580; import java.awt.Color; import java.util.Random; /** * * @author julius */ public class NeuronDemo01 extends javax.swing.JFrame { /** Creates new form NeuronDemo01 */ public NeuronDemo01() { initComponents(); this.setSize(740,500); this.setVisible(true); } /** 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. */ private void initComponents() {//GEN-BEGIN:initComponents jSlider1 = new javax.swing.JSlider(); jButton1 = new javax.swing.JButton(); n01 = new javax.swing.JPanel(); n02 = new javax.swing.JPanel(); n03 = new javax.swing.JPanel(); jSlider2 = new javax.swing.JSlider(); jSlider3 = new javax.swing.JSlider(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); getContentPane().setLayout(null); setBackground(new java.awt.Color(0, 153, 153)); setFont(new java.awt.Font("Arial", 0, 12)); setForeground(java.awt.Color.red); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jSlider1.setBackground(new java.awt.Color(255, 0, 102)); jSlider1.setMajorTickSpacing(50); jSlider1.setMaximum(255); jSlider1.setOrientation(javax.swing.JSlider.VERTICAL); jSlider1.setPaintLabels(true); jSlider1.setPaintTicks(true); jSlider1.setSnapToTicks(true); jSlider1.setToolTipText("Red Value"); getContentPane().add(jSlider1); jSlider1.setBounds(270, 200, 51, 190); jButton1.setBackground(new java.awt.Color(255, 153, 255)); jButton1.setText("Set Color"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(240, 430, 100, 23); n01.setBackground(new java.awt.Color(255, 255, 204)); getContentPane().add(n01); n01.setBounds(270, 100, 50, 40); n02.setBackground(new java.awt.Color(255, 255, 204)); getContentPane().add(n02); n02.setBounds(340, 100, 50, 40); n03.setBackground(new java.awt.Color(255, 255, 204)); getContentPane().add(n03); n03.setBounds(410, 100, 50, 40); jSlider2.setBackground(new java.awt.Color(0, 204, 102)); jSlider2.setMajorTickSpacing(50); jSlider2.setMaximum(255); jSlider2.setOrientation(javax.swing.JSlider.VERTICAL); jSlider2.setPaintLabels(true); jSlider2.setPaintTicks(true); jSlider2.setToolTipText("Green Value"); getContentPane().add(jSlider2); jSlider2.setBounds(330, 200, 60, 190); jSlider3.setBackground(new java.awt.Color(0, 102, 255)); jSlider3.setMajorTickSpacing(50); jSlider3.setMaximum(255); jSlider3.setOrientation(javax.swing.JSlider.VERTICAL); jSlider3.setPaintLabels(true); jSlider3.setPaintTicks(true); jSlider3.setToolTipText("Blue Value"); getContentPane().add(jSlider3); jSlider3.setBounds(400, 200, 60, 190); jLabel1.setFont(new java.awt.Font("MS Sans Serif", 0, 10)); jLabel1.setForeground(new java.awt.Color(51, 51, 255)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Neuron 1"); getContentPane().add(jLabel1); jLabel1.setBounds(270, 70, 50, 14); jLabel2.setFont(new java.awt.Font("MS Sans Serif", 0, 10)); jLabel2.setForeground(new java.awt.Color(51, 51, 255)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("Neuron 2"); getContentPane().add(jLabel2); jLabel2.setBounds(340, 70, 50, 14); jLabel3.setFont(new java.awt.Font("MS Sans Serif", 0, 10)); jLabel3.setForeground(new java.awt.Color(51, 51, 255)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Neuron 3"); getContentPane().add(jLabel3); jLabel3.setBounds(410, 70, 50, 14); jButton2.setBackground(new java.awt.Color(0, 204, 204)); jButton2.setText("Random Auto Mode"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2); jButton2.setBounds(360, 430, 150, 23); pack(); }//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: Random random =new Random(); for (int i = 0; i < 50; i++) { try { Thread.sleep(500); } catch (InterruptedException ie) { } jSlider1.setValue(random.nextInt(255)); jSlider1.paint(jSlider1.getGraphics()); jSlider2.setValue(random.nextInt(255)); jSlider2.paint(jSlider2.getGraphics()); jSlider3.setValue(random.nextInt(255)); jSlider3.paint(jSlider3.getGraphics()); autoRun(); } }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: n03.setBackground(n02.getBackground()); n02.setBackground(n01.getBackground()); n01.setBackground(new Color(jSlider1.getValue(), jSlider2.getValue(), jSlider3.getValue())); }//GEN-LAST:event_jButton1ActionPerformed /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit(0); }//GEN-LAST:event_exitForm /** * @param args the command line arguments */ public static void main(String args[]) { new NeuronDemo01().show(); } public void autoRun() { n03.setBackground(n02.getBackground()); n03.paint(n03.getGraphics()); n02.setBackground(n01.getBackground()); n02.paint(n02.getGraphics()); n01.setBackground(new Color(jSlider1.getValue(), jSlider2.getValue(), jSlider3.getValue())); n01.paint(n01.getGraphics()); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JSlider jSlider1; private javax.swing.JSlider jSlider2; private javax.swing.JSlider jSlider3; private javax.swing.JPanel n01; private javax.swing.JPanel n02; private javax.swing.JPanel n03; // End of variables declaration//GEN-END:variables }