Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class convertidorGUI extends javax.swing.JFrame {
- public convertidorGUI() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- tempVar = new javax.swing.JTextField();
- celciusLabel = new javax.swing.JLabel();
- convertTemp = new javax.swing.JButton();
- farLabel = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Convertidor");
- tempVar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- tempVarActionPerformed(evt);
- }
- });
- celciusLabel.setText("Celcius");
- convertTemp.setText("Convertir");
- convertTemp.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- convertTempActionPerformed(evt);
- }
- });
- farLabel.setText("Fahrenheit");
- 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(convertTemp)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(farLabel))
- .addGroup(layout.createSequentialGroup()
- .addComponent(tempVar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(celciusLabel)))
- .addContainerGap(40, Short.MAX_VALUE))
- );
- layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {convertTemp, tempVar});
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(tempVar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(celciusLabel))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(convertTemp)
- .addComponent(farLabel))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void convertTempActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertTempActionPerformed
- //Parse degrees Celsius as a double and convert to Fahrenheit.
- int tempFahr = (int)((Double.parseDouble(tempVar.getText()))
- * 1.8 + 32);
- farLabel.setText(tempFahr + " Fahrenheit");
- }//GEN-LAST:event_convertTempActionPerformed
- private void tempVarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tempVarActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_tempVarActionPerformed
- public static void main(String args[]) {
- //<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(convertidorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(convertidorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(convertidorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(convertidorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new convertidorGUI().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JLabel celciusLabel;
- private javax.swing.JButton convertTemp;
- private javax.swing.JLabel farLabel;
- private javax.swing.JTextField tempVar;
- // End of variables declaration//GEN-END:variables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement