/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MainWindow.java
*
*
*/
package Aplikasi;
/**
*
* @author XXXX
*/
public class MainWindow extends javax.swing.JFrame {
/** Creates new form MainWindow */
public MainWindow() {
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")
////GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
tfInput = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
tfResult = new javax.swing.JTextField();
btResult = new javax.swing.JButton();
btClear = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Farenheit");
tfInput.setText("0");
tfInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfInputActionPerformed(evt);
}
});
jLabel4.setText("Celcius");
tfResult.setText("0");
tfResult.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfResultActionPerformed(evt);
}
});
btResult.setText("OK");
btResult.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btResultActionPerformed(evt);
}
});
btClear.setText("RESET");
btClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btClearActionPerformed(evt);
}
});
jLabel2.setText("°F");
jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 36));
jLabel5.setText("KONVERSI SUHU");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jLabel8.setText("°C");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel4))
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfResult, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel2))))
.addGap(109, 109, 109)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(btClear, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
.addGap(89, 89, 89)
.addComponent(btResult, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addGap(164, 164, 164))
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addComponent(jLabel5)
.addContainerGap(101, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel5)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel1))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jLabel8)
.addComponent(tfResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btClear)
.addComponent(btResult)))
.addContainerGap(72, Short.MAX_VALUE))
);
pack();
}// //GEN-END:initComponents
private void btResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResultActionPerformed
Integer c = new Integer(tfInput.getText());
Integer f = new Integer(tfResult.getText());
if(c>0&&f>0)
{jTextField1.setText("Masukkan Salah Satu !");
}
else if (c>0) //
{
int hasil;
hasil = (c-32)*5/9;
jTextField1.setText("KONVERSI SUHU dari "+c+"°F adalah "+hasil+"°C");
tfResult.setText(""+hasil);
}
else if(f>0)
{
int hasil;
hasil = f*9/5+32;
jTextField1.setText("KONVERSI SUHU dari "+f+"°C adalah "+hasil+"°F");
tfInput.setText(""+hasil);
}
}//GEN-LAST:event_btResultActionPerformed
private void btClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearActionPerformed
tfResult.setText("0");
tfInput.setText("0");
jTextField1.setText("");
}//GEN-LAST:event_btClearActionPerformed
private void tfInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfInputActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfInputActionPerformed
private void tfResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfResultActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfResultActionPerformed
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btClear;
private javax.swing.JButton btResult;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField tfInput;
private javax.swing.JTextField tfResult;
// End of variables declaration//GEN-END:variables
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MainWindow.java
*
*
*/
package Aplikasi;
/**
*
* @author XXXX
*/
public class MainWindow extends javax.swing.JFrame {
/** Creates new form MainWindow */
public MainWindow() {
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() {
jLabel1 = new javax.swing.JLabel();
tfInput = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
tfResult = new javax.swing.JTextField();
btResult = new javax.swing.JButton();
btClear = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Farenheit");
tfInput.setText("0");
tfInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfInputActionPerformed(evt);
}
});
jLabel4.setText("Celcius");
tfResult.setText("0");
tfResult.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfResultActionPerformed(evt);
}
});
btResult.setText("OK");
btResult.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btResultActionPerformed(evt);
}
});
btClear.setText("RESET");
btClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btClearActionPerformed(evt);
}
});
jLabel2.setText("°F");
jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 36));
jLabel5.setText("KONVERSI SUHU");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jLabel8.setText("°C");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel4))
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfResult, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel2))))
.addGap(109, 109, 109)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(btClear, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
.addGap(89, 89, 89)
.addComponent(btResult, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addGap(164, 164, 164))
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addComponent(jLabel5)
.addContainerGap(101, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel5)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tfInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel1))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jLabel8)
.addComponent(tfResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btClear)
.addComponent(btResult)))
.addContainerGap(72, Short.MAX_VALUE))
);
pack();
}// //GEN-END:initComponents
private void btResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResultActionPerformed
Integer c = new Integer(tfInput.getText());
Integer f = new Integer(tfResult.getText());
if(c>0&&f>0)
{jTextField1.setText("Masukkan Salah Satu !");
}
else if (c>0) //
{
int hasil;
hasil = (c-32)*5/9;
jTextField1.setText("KONVERSI SUHU dari "+c+"°F adalah "+hasil+"°C");
tfResult.setText(""+hasil);
}
else if(f>0)
{
int hasil;
hasil = f*9/5+32;
jTextField1.setText("KONVERSI SUHU dari "+f+"°C adalah "+hasil+"°F");
tfInput.setText(""+hasil);
}
}//GEN-LAST:event_btResultActionPerformed
private void btClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearActionPerformed
tfResult.setText("0");
tfInput.setText("0");
jTextField1.setText("");
}//GEN-LAST:event_btClearActionPerformed
private void tfInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfInputActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfInputActionPerformed
private void tfResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfResultActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfResultActionPerformed
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btClear;
private javax.swing.JButton btResult;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField tfInput;
private javax.swing.JTextField tfResult;
// End of variables declaration//GEN-END:variables
}


0 komentar:
Posting Komentar