Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /*
  7.  * BinaryCounterFrame.java
  8.  *
  9.  * Created on Apr 21, 2012, 7:35:25 PM
  10.  */
  11.  
  12. package testPack;
  13.  
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16.  
  17. /**
  18.  *
  19.  * @author TestSignal
  20.  */
  21. public class BinaryCounterFrame extends javax.swing.JFrame {
  22.  
  23.     /** Creates new form BinaryCounterFrame */
  24.     CommExp obj;
  25.     int count=0;
  26.  
  27.     public BinaryCounterFrame()
  28.     {
  29.         try {
  30.             obj = new CommExp();
  31.             obj.connect("COM26");
  32.             obj.changeDTR(false);
  33.             obj.changeRTS(false);
  34.  
  35.             initComponents();
  36.         } catch (Exception ex) {
  37.             Logger.getLogger(BinaryCounterFrame.class.getName()).log(Level.SEVERE, null, ex);
  38.         }
  39.     }
  40.  
  41.     /** This method is called from within the constructor to
  42.      * initialize the form.
  43.      * WARNING: Do NOT modify this code. The content of this method is
  44.      * always regenerated by the Form Editor.
  45.      */
  46.     @SuppressWarnings("unchecked")
  47.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  48.     private void initComponents() {
  49.  
  50.         jButton1 = new javax.swing.JButton();
  51.         jButton2 = new javax.swing.JButton();
  52.         jLabel1 = new javax.swing.JLabel();
  53.  
  54.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  55.  
  56.         jButton1.setText("decrease");
  57.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  58.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  59.                 jButton1ActionPerformed(evt);
  60.             }
  61.         });
  62.  
  63.         jButton2.setText("increase");
  64.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  65.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  66.                 jButton2ActionPerformed(evt);
  67.             }
  68.         });
  69.  
  70.         jLabel1.setText("2 Bit Binary Counter - RS232 INTERFACE");
  71.  
  72.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  73.         getContentPane().setLayout(layout);
  74.         layout.setHorizontalGroup(
  75.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76.             .addGroup(layout.createSequentialGroup()
  77.                 .addGap(54, 54, 54)
  78.                 .addComponent(jButton1)
  79.                 .addGap(87, 87, 87)
  80.                 .addComponent(jButton2)
  81.                 .addContainerGap(85, Short.MAX_VALUE))
  82.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  83.                 .addContainerGap(84, Short.MAX_VALUE)
  84.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
  85.                 .addContainerGap())
  86.         );
  87.         layout.setVerticalGroup(
  88.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89.             .addGroup(layout.createSequentialGroup()
  90.                 .addGap(24, 24, 24)
  91.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
  92.                 .addGap(27, 27, 27)
  93.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  94.                     .addComponent(jButton1)
  95.                     .addComponent(jButton2))
  96.                 .addContainerGap(97, Short.MAX_VALUE))
  97.         );
  98.  
  99.         pack();
  100.     }// </editor-fold>//GEN-END:initComponents
  101.  
  102.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  103.  
  104.         if(count>0)
  105.             count--;
  106.  
  107.         else
  108.             count=3;
  109.  
  110.         setupLed();
  111.     }//GEN-LAST:event_jButton1ActionPerformed
  112.  
  113.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  114.  
  115.         if(count<3)
  116.             count++;
  117.  
  118.         else
  119.             count=0;
  120.  
  121.         setupLed();
  122.  
  123.     }//GEN-LAST:event_jButton2ActionPerformed
  124.  
  125.     /**
  126.     * @param args the command line arguments
  127.     */
  128.     public static void main(String args[]) {
  129.         java.awt.EventQueue.invokeLater(new Runnable() {
  130.             public void run() {
  131.                 BinaryCounterFrame f1=new BinaryCounterFrame();
  132.                 f1.setTitle("2-BIT BINARY COUNTER");
  133.                 f1.setVisible(true);
  134.  
  135.             }
  136.         });
  137.     }
  138.  
  139.     // Variables declaration - do not modify//GEN-BEGIN:variables
  140.     private javax.swing.JButton jButton1;
  141.     private javax.swing.JButton jButton2;
  142.     private javax.swing.JLabel jLabel1;
  143.     // End of variables declaration//GEN-END:variables
  144.  
  145.     private void setupLed() {
  146.  
  147.         switch(count)
  148.         {
  149.             case 0:
  150.                         obj.changeDTR(false);
  151.             obj.changeRTS(false);
  152.                         break;
  153.  
  154.                 case 1:
  155.             obj.changeDTR(true);
  156.             obj.changeRTS(false);
  157.                         break;
  158.  
  159.             case 2:
  160.             obj.changeDTR(false);
  161.             obj.changeRTS(true);
  162.                         break;
  163.             case 3:
  164.             obj.changeDTR(true);
  165.             obj.changeRTS(true);
  166.                         break;
  167.  
  168.  
  169.     }
  170.  
  171.     }
  172.  
  173. }