/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Test;
/**
*
* @author Shitney Lee
*/
public class TestAppGUI extends javax.swing.JFrame {
/**
* Creates new form TestAppGUI
*/
public TestAppGUI() {
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() {
tempTextField1 = new javax.swing.JTextField();
convertButton1 = new javax.swing.JButton();
celsiusLabel1 = new javax.swing.JLabel();
fahrenheitLabel1 = new javax.swing.JLabel();
fahrenheitLabel2 = new javax.swing.JLabel();
celsiusLabel2 = new javax.swing.JLabel();
convertButton2 = new javax.swing.JButton();
tempTextField2 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Temperature Converter");
tempTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tempTextField1ActionPerformed(evt);
}
});
convertButton1.setText("Convert!");
convertButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
convertButton1ActionPerformed(evt);
}
});
celsiusLabel1.setText("Celsius");
fahrenheitLabel1.setText("Fahrenheit");
fahrenheitLabel2.setText("Fahrenheit");
celsiusLabel2.setText("Celsius");
convertButton2.setText("jButton1");
convertButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
convertButton2ActionPerformed(evt);
}
});
tempTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tempTextField2ActionPerformed(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)
.addComponent(tempTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(convertButton1)
.addComponent(convertButton2)
.addComponent(tempTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(celsiusLabel2)
.addComponent(fahrenheitLabel2)
.addComponent(celsiusLabel1)
.addComponent(fahrenheitLabel1))
.addContainerGap(160, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {convertButton1, tempTextField1});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {convertButton2, tempTextField2});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tempTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(celsiusLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(convertButton1)
.addComponent(fahrenheitLabel1))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(fahrenheitLabel2)
.addComponent(tempTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(celsiusLabel2)
.addComponent(convertButton2))
.addContainerGap(74, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void tempTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void convertButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int tempFahr1;
tempFahr1 = (int)((Double.parseDouble(tempTextField1.getText()))
* 1.8 + 32);
fahrenheitLabel1.setText(tempFahr1 + " Fahrenheit");
}
private void tempTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void convertButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int tempCels2;
tempCels2 = (int)((Double.parseDouble(tempTextField2.getText()))
- 32 * 5.0 / 9.0) ;
celsiusLabel2.setText(tempCels2 + " Celsius");
}
/**
* @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(TestAppGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TestAppGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TestAppGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TestAppGUI.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 TestAppGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel celsiusLabel1;
private javax.swing.JLabel celsiusLabel2;
private javax.swing.JButton convertButton1;
private javax.swing.JButton convertButton2;
private javax.swing.JLabel fahrenheitLabel1;
private javax.swing.JLabel fahrenheitLabel2;
private javax.swing.JTextField tempTextField1;
private javax.swing.JTextField tempTextField2;
// End of variables declaration
}