/*
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.
 */ 

/*
 * CelsiusConverterGUI.java 
 */

//package learn;

public class CelsiusConverterGUI extends javax.swing.JFrame {
    
    /** Creates new form CelsiusConverterGUI */
    public CelsiusConverterGUI() {
        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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        tempTextField = new javax.swing.JTextField();
        celsiusLabel = new javax.swing.JLabel();
        convertButton = new javax.swing.JButton();
        fahrenheitLabel = new javax.swing.JLabel();
        boredButton = new javax.swing.JButton();
        boredLabel = new javax.swing.JLabel();

        tempTextField.setFont(tempTextField.getFont().deriveFont(20.0F));
        celsiusLabel.setFont(celsiusLabel.getFont().deriveFont(20.0F));
        convertButton.setFont(convertButton.getFont().deriveFont(20.0F));
        fahrenheitLabel.setFont(fahrenheitLabel.getFont().deriveFont(20.0F));
        boredButton.setFont(boredButton.getFont().deriveFont(20.0F));
        boredLabel.setFont(boredLabel.getFont().deriveFont(20.0F));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Celsius Converter");

        tempTextField.setText("0");
        celsiusLabel.setText("Celsius");
        convertButton.setText("Convert");
        fahrenheitLabel.setText("Fahrenheit");
        boredButton.setText("I'm bored");
        boredLabel.setText("");

        convertButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                convertButtonActionPerformed(evt);
            }
        });

        boredButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boredLabel.setText(new java.util.Date().toString());
            }
        });

        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(tempTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(celsiusLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(convertButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fahrenheitLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(boredButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boredLabel)))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {convertButton, tempTextField, boredButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tempTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(celsiusLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(convertButton)
                    .addComponent(fahrenheitLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(boredButton)
                     .addComponent(boredLabel))
              .addContainerGap(21, Short.MAX_VALUE))
        );
        setPreferredSize(new java.awt.Dimension(500,200));
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed
        //Parse degrees Celsius as a double and convert to Fahrenheit
        Thread bg = new Thread() {
            @Override
            public void run() {
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        fahrenheitLabel.setText("Working...");
                    }
                });
                    
                String t = tempTextField.getText();
                final int tempFahr = (int)(Double.parseDouble(t) * 1.8 + 32);
                
                long s = 0;
                for (int j=0; j<7; j++) {
                    for (int i=0; i<Integer.MAX_VALUE; i++) {
                        s += 1;
                    }
                }
                
                try { Thread.sleep(7000); }
                catch (Exception ex) {}

                javax.swing.SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        fahrenheitLabel.setText(tempFahr + " Fahrenheit");
                    }
                });
            }
        };
        
        bg.start();

    }//GEN-LAST:event_convertButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CelsiusConverterGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField tempTextField;
    private javax.swing.JLabel celsiusLabel;
    private javax.swing.JButton convertButton;
    private javax.swing.JLabel fahrenheitLabel;
    private javax.swing.JButton boredButton;
    private javax.swing.JLabel boredLabel;
    // End of variables declaration//GEN-END:variables
    
}

