/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* BinaryCounterFrame.java
*
* Created on Apr 21, 2012, 7:35:25 PM
*/
package testPack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author TestSignal
*/
public class BinaryCounterFrame extends javax.swing.JFrame {
/** Creates new form BinaryCounterFrame */
CommExp obj;
int count=0;
public BinaryCounterFrame()
{
try {
obj = new CommExp();
obj.connect("COM26");
obj.changeDTR(false);
obj.changeRTS(false);
initComponents();
} catch (Exception ex) {
Logger.getLogger(BinaryCounterFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("decrease");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("increase");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setText("2 Bit Binary Counter - RS232 INTERFACE");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jButton1)
.addGap(87, 87, 87)
.addComponent(jButton2)
.addContainerGap(85, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(84, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(97, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if(count>0)
count--;
else
count=3;
setupLed();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
if(count<3)
count++;
else
count=0;
setupLed();
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
BinaryCounterFrame f1=new BinaryCounterFrame();
f1.setTitle("2-BIT BINARY COUNTER");
f1.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
private void setupLed() {
switch(count)
{
case 0:
obj.changeDTR(false);
obj.changeRTS(false);
break;
case 1:
obj.changeDTR(true);
obj.changeRTS(false);
break;
case 2:
obj.changeDTR(false);
obj.changeRTS(true);
break;
case 3:
obj.changeDTR(true);
obj.changeRTS(true);
break;
}
}
}