private void ConversionButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_ConversionButtonActionPerformed // TODO add your handling code here: String inputText = InputDataField.getText(); clearOutput(); if (inputIsValid(inputText)) { Double Tcel = Double.valueOf(InputDataField.getText()); Double Tfah = 1.8 * Tcel + 32; OutputDataField.setText("" + Tfah); } } // GEN-LAST:event_ConversionButtonActionPerformed
/** * 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">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); AuthorLabel = new javax.swing.JLabel(); InputDataField = new javax.swing.JTextField(); ConversionButton = new javax.swing.JButton(); OutputDataField = new javax.swing.JTextField(); InputLabel = new javax.swing.JLabel(); OutputLabel = new javax.swing.JLabel(); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Conversor de Temperatura"); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setResizable(false); AuthorLabel.setText(" Héctor Garbisu DiU 2015"); InputDataField.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { InputDataFieldActionPerformed(evt); } }); ConversionButton.setText("Convertir"); ConversionButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ConversionButtonActionPerformed(evt); } }); InputLabel.setText("Temperatura (Celsius)"); OutputLabel.setText("Temperatura (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) .addComponent(AuthorLabel) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addComponent( InputDataField, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement .RELATED) .addComponent(ConversionButton)) .addComponent(InputLabel)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(OutputLabel) .addComponent( OutputDataField, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addContainerGap(34, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(InputLabel, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(OutputLabel, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( InputDataField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ConversionButton) .addComponent( OutputDataField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(29, 29, 29) .addComponent(AuthorLabel) .addContainerGap())); pack(); } // </editor-fold>//GEN-END:initComponents