Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package pantalla;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import javax.swing.JOptionPane;
- /**
- *
- * @author LABORATORIO B1
- */
- public class Temperatura extends javax.swing.JFrame {
- /**
- * Creates new form Temperatura
- */
- public Temperatura() {
- System.gc();
- initComponents();
- this.setLocationRelativeTo(null);
- String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
- this.lblFecha.setText(date);
- this.setTitle("Universidad Politecnica Salesiana Sede Guayaquil");
- this.ResultadoField.setEditable(false);
- }
- /**
- * 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() {
- FondoInt = new javax.swing.JPanel();
- lblTitulo = new javax.swing.JLabel();
- DatoF = new javax.swing.JLabel();
- datoFieldF = new javax.swing.JTextField();
- DatoR = new javax.swing.JLabel();
- DecoBtn1 = new javax.swing.JPanel();
- CalBtn = new javax.swing.JButton();
- DecoBtn2 = new javax.swing.JPanel();
- CleanBtn = new javax.swing.JButton();
- btnSalir = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- ResultadoField = new javax.swing.JTextArea();
- VersionNumber = new javax.swing.JLabel();
- lblFecha = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent evt) {
- formWindowClosing(evt);
- }
- });
- FondoInt.setBackground(new java.awt.Color(240, 133, 53));
- lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- lblTitulo.setForeground(new java.awt.Color(255, 255, 255));
- lblTitulo.setText("CONVERTIDOR DE TEMPERATURAS");
- DatoF.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- DatoF.setForeground(new java.awt.Color(255, 255, 255));
- DatoF.setText("Resultado:");
- datoFieldF.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- datoFieldFActionPerformed(evt);
- }
- });
- datoFieldF.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(java.awt.event.KeyEvent evt) {
- datoFieldFKeyTyped(evt);
- }
- });
- DatoR.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- DatoR.setForeground(new java.awt.Color(255, 255, 255));
- DatoR.setText("Dato °F:");
- DecoBtn1.setBackground(new java.awt.Color(220, 145, 31));
- DecoBtn1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- DecoBtn1.setForeground(new java.awt.Color(220, 145, 31));
- CalBtn.setBackground(new java.awt.Color(255, 204, 102));
- CalBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/calculator.png"))); // NOI18N
- CalBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- CalBtnActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout DecoBtn1Layout = new javax.swing.GroupLayout(DecoBtn1);
- DecoBtn1.setLayout(DecoBtn1Layout);
- DecoBtn1Layout.setHorizontalGroup(
- DecoBtn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DecoBtn1Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(CalBtn)
- .addContainerGap())
- );
- DecoBtn1Layout.setVerticalGroup(
- DecoBtn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DecoBtn1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(CalBtn))
- );
- DecoBtn2.setBackground(new java.awt.Color(220, 145, 31));
- DecoBtn2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- DecoBtn2.setForeground(new java.awt.Color(220, 145, 31));
- CleanBtn.setBackground(new java.awt.Color(255, 204, 102));
- CleanBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/clean.png"))); // NOI18N
- CleanBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- CleanBtnActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout DecoBtn2Layout = new javax.swing.GroupLayout(DecoBtn2);
- DecoBtn2.setLayout(DecoBtn2Layout);
- DecoBtn2Layout.setHorizontalGroup(
- DecoBtn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(DecoBtn2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(CleanBtn)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- DecoBtn2Layout.setVerticalGroup(
- DecoBtn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(CleanBtn, javax.swing.GroupLayout.Alignment.TRAILING)
- );
- btnSalir.setBackground(new java.awt.Color(255, 51, 0));
- btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button.png"))); // NOI18N
- btnSalir.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnSalirActionPerformed(evt);
- }
- });
- ResultadoField.setColumns(20);
- ResultadoField.setRows(5);
- jScrollPane1.setViewportView(ResultadoField);
- VersionNumber.setFont(new java.awt.Font("Segoe UI", 0, 8)); // NOI18N
- VersionNumber.setForeground(new java.awt.Color(51, 51, 51));
- VersionNumber.setText("Version: Alpha 0.0.1");
- lblFecha.setFont(new java.awt.Font("Segoe UI", 0, 8)); // NOI18N
- javax.swing.GroupLayout FondoIntLayout = new javax.swing.GroupLayout(FondoInt);
- FondoInt.setLayout(FondoIntLayout);
- FondoIntLayout.setHorizontalGroup(
- FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FondoIntLayout.createSequentialGroup()
- .addComponent(VersionNumber)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnSalir))
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addGap(79, 79, 79)
- .addComponent(DatoR)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(datoFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addGap(62, 62, 62)
- .addComponent(DatoF)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addComponent(DecoBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(75, 75, 75)
- .addComponent(DecoBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addComponent(lblTitulo))
- .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(0, 85, Short.MAX_VALUE)))
- .addContainerGap())
- );
- FondoIntLayout.setVerticalGroup(
- FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(lblTitulo)
- .addGap(18, 18, 18)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(DatoR)
- .addComponent(datoFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addGap(14, 14, 14)
- .addComponent(DatoF)))
- .addGap(18, 18, 18)
- .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addComponent(DecoBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
- .addComponent(btnSalir)
- .addContainerGap())
- .addGroup(FondoIntLayout.createSequentialGroup()
- .addComponent(DecoBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(VersionNumber))))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(FondoInt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(FondoInt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void datoFieldFActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void datoFieldFKeyTyped(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- int key = evt.getKeyChar();
- boolean numeros = key >= 48 && key <= 57;
- if (!numeros){
- evt.consume();
- }
- /*
- if (.getText().trim.length() == 10){
- // .trim es para eliminar los espacios
- evt.consume();
- }
- */
- }
- private void CleanBtnActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.datoFieldF.setText("");
- this.ResultadoField.setText("");
- this.datoFieldF.requestFocus();
- }
- private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int result = JOptionPane.showConfirmDialog(null,"¿Estas Seguro que deseas Salir?", "Convertidor de Temperaturas",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE);
- if(result == JOptionPane.YES_OPTION){
- System.exit(0);
- }
- }
- private void CalBtnActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if(this.datoFieldF.getText().isEmpty()){
- JOptionPane.showMessageDialog(null, "Estimado usuario recuerde que esos campos son obligatorio para convertir");
- } else {
- int dato = Integer.parseInt(this.datoFieldF.getText());
- double resultado = (dato-32)/1.8;
- String mensaje = dato + "° F, es equivalente a" + resultado + "° C";
- this.ResultadoField.setText(mensaje);
- this.ResultadoField.setEditable(false);
- }
- }
- private void formWindowClosing(java.awt.event.WindowEvent evt) {
- // TODO add your handling code here:
- int result = JOptionPane.showConfirmDialog(null,"¿Estas Seguro que deseas Salir?", "Convertidor de Temperaturas",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE);
- if(result == JOptionPane.YES_OPTION){
- System.exit(0);
- }
- }
- 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(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Temperatura.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 Temperatura().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton CalBtn;
- private javax.swing.JButton CleanBtn;
- private javax.swing.JLabel DatoF;
- private javax.swing.JLabel DatoR;
- private javax.swing.JPanel DecoBtn1;
- private javax.swing.JPanel DecoBtn2;
- private javax.swing.JPanel FondoInt;
- private javax.swing.JTextArea ResultadoField;
- private javax.swing.JLabel VersionNumber;
- private javax.swing.JButton btnSalir;
- private javax.swing.JTextField datoFieldF;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JLabel lblFecha;
- private javax.swing.JLabel lblTitulo;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement