Saturday, 8 June 2013

To Convert the Units of Measurement of Length

This program , I need to convert the length of wood sheets and veneer paper and was eagerly willing a calculator. In those days the internet was not easily available here . So i decided to make a conversion calculator for the measurements appropriate conversion.

So i share all of my friends here

/*
 * Length.java
 *
 * Created on July 21, 2008, 9:40 AM
 */

package length;

import javax.swing.JOptionPane;
/**
 *
 * @author Saeed Ahmad
 */
public class Length extends javax.swing.JFrame {
 private Object JRootPane;


 /** Creates new form Length */
 public Length() {
 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")
 //
 private void initComponents() {

 cmOption = new javax.swing.JComboBox();
 jLabel1 = new javax.swing.JLabel();
 jLabel2 = new javax.swing.JLabel();
 jLabel3 = new javax.swing.JLabel();
 jLabel4 = new javax.swing.JLabel();
 jLabel5 = new javax.swing.JLabel();
 jLabel6 = new javax.swing.JLabel();
 txtValue = new javax.swing.JTextField();
 jButton1 = new javax.swing.JButton();

 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 setTitle("Length Calc Beta Ver.");
 setResizable(false);
 addWindowListener(new java.awt.event.WindowAdapter() {
 public void windowActivated(java.awt.event.WindowEvent evt) {
 formWindowActivated(evt);
 }
 public void windowOpened(java.awt.event.WindowEvent evt) {
 formWindowOpened(evt);
 }
 });

 cmOption.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MM", "CM", "Inch", "Feet", "Meter", "Kilo Meter" }));
 cmOption.addItemListener(new java.awt.event.ItemListener() {
 public void itemStateChanged(java.awt.event.ItemEvent evt) {
 cmOptionItemStateChanged(evt);
 }
 });
 cmOption.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 cmOptionActionPerformed(evt);
 }
 });

 jLabel1.setText("Your Choice");

 jLabel2.setText("jLabel2");

 jLabel3.setText("jLabel2");

 jLabel4.setText("jLabel2");

 jLabel5.setText("jLabel2");

 jLabel6.setText("jLabel2");

 txtValue.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
 txtValue.setText("0");
 txtValue.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 txtValueActionPerformed(evt);
 }
 });

 jButton1.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
 jButton1.setText("Ok");
 jButton1.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton1ActionPerformed(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()
 .addContainerGap()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
 .addGap(42, 42, 42))
 .addGroup(layout.createSequentialGroup()
 .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
 .addGap(42, 42, 42))
 .addGroup(layout.createSequentialGroup()
 .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
 .addGap(42, 42, 42))
 .addGroup(layout.createSequentialGroup()
 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addContainerGap())
 .addGroup(layout.createSequentialGroup()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
 .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
 .addComponent(txtValue, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(jButton1, 0, 0, Short.MAX_VALUE))
 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(cmOption, 0, 109, Short.MAX_VALUE)))
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
 );
 layout.setVerticalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(cmOption))
 .addGap(1, 1, 1)
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(txtValue, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jButton1))
 .addGap(18, 18, 18)
 .addComponent(jLabel2)
 .addGap(15, 15, 15)
 .addComponent(jLabel3)
 .addGap(14, 14, 14)
 .addComponent(jLabel4)
 .addGap(18, 18, 18)
 .addComponent(jLabel5)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addComponent(jLabel6)
 .addContainerGap())
 );

 pack();
 }//

private void cmOptionActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void formWindowActivated(java.awt.event.WindowEvent evt) {



}

private void cmOptionItemStateChanged(java.awt.event.ItemEvent evt) {
 Double value=(Double) Double.parseDouble(txtValue.getText());
 String x= (String) cmOption.getSelectedItem();
 int result= x.compareTo("MM");
 if (result==0){
 jLabel2.setText("CM: "+value/10);
 jLabel3.setText("Inch: "+value/25.4);
 jLabel4.setText("Feet: "+value/2.54*1/12.0);
 jLabel5.setText("Meter: "+value/1000);
 jLabel6.setText("Kilo Meter: "+value/1000000);
 }
 result= x.compareTo("CM");
 if (result==0){
 jLabel2.setText("MM: "+value*10.0);
 jLabel3.setText("Inch: "+value/2.54);
 jLabel4.setText("Feet: "+value/2.54*1/12);
 jLabel5.setText("Meter: "+value/100);
 jLabel6.setText("Kilo Meter: "+value/100000);
 }
 result= x.compareTo("Inch");
 if (result==0){
 jLabel2.setText("MM: "+value*25.4);
 jLabel3.setText("CM: "+value*2.54);
 jLabel4.setText("Feet: "+value/12.0);
 jLabel5.setText("Meter: "+value*0.0254);
 jLabel6.setText("Kilo Meter: "+value*0.0000254);
 }
 result= x.compareTo("Feet");
 if (result==0){
 jLabel2.setText("MM: "+value*304.8);
 jLabel3.setText("CM: "+value*30.48);
 jLabel4.setText("Inch: "+value*12.0);
 jLabel5.setText("Meter: "+value*0.3048);
 jLabel6.setText("Kilo Meter: "+value*0.0003048);
 }
result= x.compareTo("Meter");
 if (result==0){
 jLabel2.setText("MM: "+value*1000.0);
 jLabel3.setText("CM: "+value*100.0);
 jLabel4.setText("Inch: "+value*39.3700788);
 jLabel5.setText("Feet: "+value*3.2808399);
 jLabel6.setText("Kilo Meter: "+value/1000.0);
 }
result= x.compareTo("Kilo Meter");
 if (result==0){
 jLabel2.setText("MM: "+value/1000000.0);
 jLabel3.setText("CM: "+value/100000.0);
 jLabel4.setText("Inch: "+value*3280.8399);
 jLabel5.setText("Feet: "+value*273.403325);
 jLabel6.setText("Meter: "+value/1000.0);
 }
}

private void txtValueActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 Double value=(Double) Double.parseDouble(txtValue.getText());
 String x= (String) cmOption.getSelectedItem();
 int result= x.compareTo("MM");
 if (result==0){
 jLabel2.setText("CM: "+value/10);
 jLabel3.setText("Inch: "+value/25.4);
 jLabel4.setText("Feet: "+value/2.54*1/12.0);
 jLabel5.setText("Meter: "+value/1000);
 jLabel6.setText("Kilo Meter: "+value/1000000);
 }
 result= x.compareTo("CM");
 if (result==0){
 jLabel2.setText("MM: "+value*10.0);
 jLabel3.setText("Inch: "+value/2.54);
 jLabel4.setText("Feet: "+value/2.54*1/12);
 jLabel5.setText("Meter: "+value/100);
 jLabel6.setText("Kilo Meter: "+value/100000);
 }
 result= x.compareTo("Inch");
 if (result==0){
 jLabel2.setText("MM: "+value*25.4);
 jLabel3.setText("CM: "+value*2.54);
 jLabel4.setText("Feet: "+value/12.0);
 jLabel5.setText("Meter: "+value*0.0254);
 jLabel6.setText("Kilo Meter: "+value*0.0000254);
 }
 result= x.compareTo("Feet");
 if (result==0){
 jLabel2.setText("MM: "+value*304.8);
 jLabel3.setText("CM: "+value*30.48);
 jLabel4.setText("Inch: "+value*12.0);
 jLabel5.setText("Meter: "+value*0.3048);
 jLabel6.setText("Kilo Meter: "+value*0.0003048);
 }
result= x.compareTo("Meter");
 if (result==0){
 jLabel2.setText("MM: "+value*1000.0);
 jLabel3.setText("CM: "+value*100.0);
 jLabel4.setText("Inch: "+value*39.3700788);
 jLabel5.setText("Feet: "+value*3.2808399);
 jLabel6.setText("Kilo Meter: "+value/1000.0);
 }
result= x.compareTo("Kilo Meter");
 if (result==0){
 jLabel2.setText("MM: "+value/1000000.0);
 jLabel3.setText("CM: "+value/100000.0);
 jLabel4.setText("Inch: "+value*3280.8399);
 jLabel5.setText("Feet: "+value*273.403325);
 jLabel6.setText("Meter: "+value/1000.0);
 }
}

private void formWindowOpened(java.awt.event.WindowEvent evt) {
 setLocationRelativeTo(null);
 jLabel2.setText("CM:");
 jLabel3.setText("Inches:");
 jLabel4.setText("Foot:");
 jLabel5.setText("Meter:");
 jLabel6.setText("Kilo Meter:");
 JOptionPane.showMessageDialog(null,"Length Calculator Beta ver \n Designed By: \n Mr. Saeed Ahmad \n Cell#+92-301-7640931 \n Email: mbit.dbms@gmail.com", "Length Calculator", JOptionPane.INFORMATION_MESSAGE);
}

 /**
 * @param args the command line arguments
 */
 public static void main(String args[]) {
 java.awt.EventQueue.invokeLater(new Runnable() {
     @Override
 public void run() {
 new Length().setVisible(true);
 }
 });
 }

 // Variables declaration - do not modify
 private javax.swing.JComboBox cmOption;
 private javax.swing.JButton jButton1;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JTextField txtValue;
 // End of variables declaration

}
 

No comments:

Post a Comment