Advertisement
Diego1764

Interfaz de Temperatura

Feb 19th, 2025
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.07 KB | Source Code | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package pantalla;
  7.  
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import javax.swing.JOptionPane;
  11.  
  12. /**
  13.  *
  14.  * @author LABORATORIO B1
  15.  */
  16. public class Temperatura extends javax.swing.JFrame {
  17.  
  18.     /**
  19.      * Creates new form Temperatura
  20.      */
  21.     public Temperatura() {
  22.         System.gc();
  23.         initComponents();
  24.         this.setLocationRelativeTo(null);
  25.         String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
  26.         this.lblFecha.setText(date);
  27.         this.setTitle("Universidad Politecnica Salesiana Sede Guayaquil");
  28.         this.ResultadoField.setEditable(false);
  29.     }
  30.  
  31.     /**
  32.      * This method is called from within the constructor to initialize the form.
  33.      * WARNING: Do NOT modify this code. The content of this method is always
  34.      * regenerated by the Form Editor.
  35.      */
  36.     @SuppressWarnings("unchecked")
  37.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  38.     private void initComponents() {
  39.  
  40.         FondoInt = new javax.swing.JPanel();
  41.         lblTitulo = new javax.swing.JLabel();
  42.         DatoF = new javax.swing.JLabel();
  43.         datoFieldF = new javax.swing.JTextField();
  44.         DatoR = new javax.swing.JLabel();
  45.         DecoBtn1 = new javax.swing.JPanel();
  46.         CalBtn = new javax.swing.JButton();
  47.         DecoBtn2 = new javax.swing.JPanel();
  48.         CleanBtn = new javax.swing.JButton();
  49.         btnSalir = new javax.swing.JButton();
  50.         jScrollPane1 = new javax.swing.JScrollPane();
  51.         ResultadoField = new javax.swing.JTextArea();
  52.         VersionNumber = new javax.swing.JLabel();
  53.         lblFecha = new javax.swing.JLabel();
  54.  
  55.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  56.         addWindowListener(new java.awt.event.WindowAdapter() {
  57.             public void windowClosing(java.awt.event.WindowEvent evt) {
  58.                 formWindowClosing(evt);
  59.             }
  60.         });
  61.  
  62.         FondoInt.setBackground(new java.awt.Color(240, 133, 53));
  63.  
  64.         lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  65.         lblTitulo.setForeground(new java.awt.Color(255, 255, 255));
  66.         lblTitulo.setText("CONVERTIDOR DE TEMPERATURAS");
  67.  
  68.         DatoF.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  69.         DatoF.setForeground(new java.awt.Color(255, 255, 255));
  70.         DatoF.setText("Resultado:");
  71.  
  72.         datoFieldF.addActionListener(new java.awt.event.ActionListener() {
  73.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  74.                 datoFieldFActionPerformed(evt);
  75.             }
  76.         });
  77.         datoFieldF.addKeyListener(new java.awt.event.KeyAdapter() {
  78.             public void keyTyped(java.awt.event.KeyEvent evt) {
  79.                 datoFieldFKeyTyped(evt);
  80.             }
  81.         });
  82.  
  83.         DatoR.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  84.         DatoR.setForeground(new java.awt.Color(255, 255, 255));
  85.         DatoR.setText("Dato °F:");
  86.  
  87.         DecoBtn1.setBackground(new java.awt.Color(220, 145, 31));
  88.         DecoBtn1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  89.         DecoBtn1.setForeground(new java.awt.Color(220, 145, 31));
  90.  
  91.         CalBtn.setBackground(new java.awt.Color(255, 204, 102));
  92.         CalBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/calculator.png"))); // NOI18N
  93.         CalBtn.addActionListener(new java.awt.event.ActionListener() {
  94.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  95.                 CalBtnActionPerformed(evt);
  96.             }
  97.         });
  98.  
  99.         javax.swing.GroupLayout DecoBtn1Layout = new javax.swing.GroupLayout(DecoBtn1);
  100.         DecoBtn1.setLayout(DecoBtn1Layout);
  101.         DecoBtn1Layout.setHorizontalGroup(
  102.             DecoBtn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DecoBtn1Layout.createSequentialGroup()
  104.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  105.                 .addComponent(CalBtn)
  106.                 .addContainerGap())
  107.         );
  108.         DecoBtn1Layout.setVerticalGroup(
  109.             DecoBtn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DecoBtn1Layout.createSequentialGroup()
  111.                 .addGap(0, 0, Short.MAX_VALUE)
  112.                 .addComponent(CalBtn))
  113.         );
  114.  
  115.         DecoBtn2.setBackground(new java.awt.Color(220, 145, 31));
  116.         DecoBtn2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  117.         DecoBtn2.setForeground(new java.awt.Color(220, 145, 31));
  118.  
  119.         CleanBtn.setBackground(new java.awt.Color(255, 204, 102));
  120.         CleanBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/clean.png"))); // NOI18N
  121.         CleanBtn.addActionListener(new java.awt.event.ActionListener() {
  122.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  123.                 CleanBtnActionPerformed(evt);
  124.             }
  125.         });
  126.  
  127.         javax.swing.GroupLayout DecoBtn2Layout = new javax.swing.GroupLayout(DecoBtn2);
  128.         DecoBtn2.setLayout(DecoBtn2Layout);
  129.         DecoBtn2Layout.setHorizontalGroup(
  130.             DecoBtn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  131.             .addGroup(DecoBtn2Layout.createSequentialGroup()
  132.                 .addContainerGap()
  133.                 .addComponent(CleanBtn)
  134.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  135.         );
  136.         DecoBtn2Layout.setVerticalGroup(
  137.             DecoBtn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  138.             .addComponent(CleanBtn, javax.swing.GroupLayout.Alignment.TRAILING)
  139.         );
  140.  
  141.         btnSalir.setBackground(new java.awt.Color(255, 51, 0));
  142.         btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button.png"))); // NOI18N
  143.         btnSalir.addActionListener(new java.awt.event.ActionListener() {
  144.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  145.                 btnSalirActionPerformed(evt);
  146.             }
  147.         });
  148.  
  149.         ResultadoField.setColumns(20);
  150.         ResultadoField.setRows(5);
  151.         jScrollPane1.setViewportView(ResultadoField);
  152.  
  153.         VersionNumber.setFont(new java.awt.Font("Segoe UI", 0, 8)); // NOI18N
  154.         VersionNumber.setForeground(new java.awt.Color(51, 51, 51));
  155.         VersionNumber.setText("Version: Alpha 0.0.1");
  156.  
  157.         lblFecha.setFont(new java.awt.Font("Segoe UI", 0, 8)); // NOI18N
  158.  
  159.         javax.swing.GroupLayout FondoIntLayout = new javax.swing.GroupLayout(FondoInt);
  160.         FondoInt.setLayout(FondoIntLayout);
  161.         FondoIntLayout.setHorizontalGroup(
  162.             FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  163.             .addGroup(FondoIntLayout.createSequentialGroup()
  164.                 .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  165.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FondoIntLayout.createSequentialGroup()
  166.                         .addComponent(VersionNumber)
  167.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  168.                         .addComponent(btnSalir))
  169.                     .addGroup(FondoIntLayout.createSequentialGroup()
  170.                         .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  171.                             .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  172.                                 .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  173.                                     .addGroup(FondoIntLayout.createSequentialGroup()
  174.                                         .addGap(79, 79, 79)
  175.                                         .addComponent(DatoR)
  176.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  177.                                         .addComponent(datoFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
  178.                                     .addGroup(FondoIntLayout.createSequentialGroup()
  179.                                         .addGap(62, 62, 62)
  180.                                         .addComponent(DatoF)
  181.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  182.                                         .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  183.                                             .addGroup(FondoIntLayout.createSequentialGroup()
  184.                                                 .addComponent(DecoBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  185.                                                 .addGap(75, 75, 75)
  186.                                                 .addComponent(DecoBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  187.                                             .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
  188.                                 .addComponent(lblTitulo))
  189.                             .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
  190.                         .addGap(0, 85, Short.MAX_VALUE)))
  191.                 .addContainerGap())
  192.         );
  193.         FondoIntLayout.setVerticalGroup(
  194.             FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  195.             .addGroup(FondoIntLayout.createSequentialGroup()
  196.                 .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
  197.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  198.                 .addComponent(lblTitulo)
  199.                 .addGap(18, 18, 18)
  200.                 .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  201.                     .addComponent(DatoR)
  202.                     .addComponent(datoFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  203.                 .addGap(18, 18, 18)
  204.                 .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  205.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
  206.                     .addGroup(FondoIntLayout.createSequentialGroup()
  207.                         .addGap(14, 14, 14)
  208.                         .addComponent(DatoF)))
  209.                 .addGap(18, 18, 18)
  210.                 .addGroup(FondoIntLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  211.                     .addGroup(FondoIntLayout.createSequentialGroup()
  212.                         .addComponent(DecoBtn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  213.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
  214.                         .addComponent(btnSalir)
  215.                         .addContainerGap())
  216.                     .addGroup(FondoIntLayout.createSequentialGroup()
  217.                         .addComponent(DecoBtn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  218.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  219.                         .addComponent(VersionNumber))))
  220.         );
  221.  
  222.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  223.         getContentPane().setLayout(layout);
  224.         layout.setHorizontalGroup(
  225.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226.             .addComponent(FondoInt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  227.         );
  228.         layout.setVerticalGroup(
  229.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  230.             .addComponent(FondoInt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  231.         );
  232.  
  233.         pack();
  234.     }// </editor-fold>                        
  235.  
  236.     private void datoFieldFActionPerformed(java.awt.event.ActionEvent evt) {                                          
  237.         // TODO add your handling code here:
  238.     }                                          
  239.  
  240.     private void datoFieldFKeyTyped(java.awt.event.KeyEvent evt) {                                    
  241.         // TODO add your handling code here:
  242.         int key = evt.getKeyChar();
  243.        
  244.         boolean numeros = key >= 48 && key <= 57;
  245.        
  246.         if (!numeros){
  247.             evt.consume();
  248.         }
  249.        
  250.         /*
  251.         if (.getText().trim.length() == 10){
  252.             // .trim es para eliminar los espacios
  253.             evt.consume();
  254.         }
  255.         */
  256.     }                                  
  257.  
  258.     private void CleanBtnActionPerformed(java.awt.event.ActionEvent evt) {                                        
  259.         // TODO add your handling code here:
  260.         this.datoFieldF.setText("");
  261.         this.ResultadoField.setText("");
  262.         this.datoFieldF.requestFocus();
  263.     }                                        
  264.  
  265.     private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {                                        
  266.         // TODO add your handling code here:
  267.         int result = JOptionPane.showConfirmDialog(null,"¿Estas Seguro que deseas Salir?", "Convertidor de Temperaturas",
  268.                 JOptionPane.YES_NO_OPTION,
  269.                 JOptionPane.QUESTION_MESSAGE);
  270.                 if(result == JOptionPane.YES_OPTION){
  271.                     System.exit(0);
  272.                 }
  273.     }                                        
  274.  
  275.     private void CalBtnActionPerformed(java.awt.event.ActionEvent evt) {                                      
  276.         // TODO add your handling code here:
  277.         if(this.datoFieldF.getText().isEmpty()){
  278.             JOptionPane.showMessageDialog(null, "Estimado usuario recuerde que esos campos son obligatorio para convertir");
  279.         } else {
  280.             int dato = Integer.parseInt(this.datoFieldF.getText());
  281.             double resultado = (dato-32)/1.8;
  282.             String mensaje = dato + "° F, es equivalente a" + resultado + "° C";
  283.             this.ResultadoField.setText(mensaje);
  284.             this.ResultadoField.setEditable(false);
  285.         }
  286.     }                                      
  287.  
  288.     private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
  289.         // TODO add your handling code here:
  290.         int result = JOptionPane.showConfirmDialog(null,"¿Estas Seguro que deseas Salir?", "Convertidor de Temperaturas",
  291.                 JOptionPane.YES_NO_OPTION,
  292.                 JOptionPane.QUESTION_MESSAGE);
  293.                 if(result == JOptionPane.YES_OPTION){
  294.                     System.exit(0);
  295.                 }
  296.     }                                  
  297.  
  298.     public static void main(String args[]) {
  299.         /* Set the Nimbus look and feel */
  300.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  301.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  302.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  303.          */
  304.         try {
  305.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  306.                 if ("Nimbus".equals(info.getName())) {
  307.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  308.                     break;
  309.                 }
  310.             }
  311.         } catch (ClassNotFoundException ex) {
  312.             java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  313.         } catch (InstantiationException ex) {
  314.             java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  315.         } catch (IllegalAccessException ex) {
  316.             java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  317.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  318.             java.util.logging.Logger.getLogger(Temperatura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  319.         }
  320.         //</editor-fold>
  321.  
  322.         /* Create and display the form */
  323.         java.awt.EventQueue.invokeLater(new Runnable() {
  324.             public void run() {
  325.                 new Temperatura().setVisible(true);
  326.             }
  327.         });
  328.     }
  329.    
  330.     // Variables declaration - do not modify                    
  331.     private javax.swing.JButton CalBtn;
  332.     private javax.swing.JButton CleanBtn;
  333.     private javax.swing.JLabel DatoF;
  334.     private javax.swing.JLabel DatoR;
  335.     private javax.swing.JPanel DecoBtn1;
  336.     private javax.swing.JPanel DecoBtn2;
  337.     private javax.swing.JPanel FondoInt;
  338.     private javax.swing.JTextArea ResultadoField;
  339.     private javax.swing.JLabel VersionNumber;
  340.     private javax.swing.JButton btnSalir;
  341.     private javax.swing.JTextField datoFieldF;
  342.     private javax.swing.JScrollPane jScrollPane1;
  343.     private javax.swing.JLabel lblFecha;
  344.     private javax.swing.JLabel lblTitulo;
  345.     // End of variables declaration                  
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement