tutostudio1

INTERFACE - CONVERSOR DE TEMPERATURA

May 4th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package conversor;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Frame;
  6. import java.awt.Label;
  7. import java.awt.Button;
  8. import java.awt.TextField;
  9. import java.awt.event.ActionListener;
  10. import javax.swing.JOptionPane;
  11.  
  12. public class Interface extends Frame {
  13.  
  14.     private Label lblTemp1;
  15.     private Label lblTemp2;
  16.     private Label lblUnidade;
  17.     private TextField txtTemperatura;
  18.     private Button btnCel;
  19.     private Button btnFa;
  20.     private Button btnKel;
  21.  
  22.     public Interface() {
  23.  
  24.         //DEFINIÇÕES DA JANELA
  25.         this.setLayout(null);
  26.         this.setResizable(false);
  27.         this.setUndecorated(false);
  28.         this.setVisible(true);
  29.         this.setBounds(100, 10, 450, 300);
  30.         this.setBackground(Color.WHITE);
  31.         this.setTitle("CONVERSOR");
  32.  
  33.         //LABEL'S
  34.         Label lblTemperatura = new Label("Temperatura:");
  35.         lblTemperatura.setBounds(50, 50, 120, 30);
  36.  
  37.         lblTemp1 = new Label("");
  38.         lblTemp1.setBounds(90, 220, 150, 30);
  39.         lblTemp1.setVisible(false);
  40.  
  41.         lblTemp2 = new Label("");
  42.         lblTemp2.setBounds(250, 220, 150, 30);
  43.         lblTemp2.setVisible(false);
  44.  
  45.         lblUnidade = new Label("");
  46.         lblUnidade.setBounds(390, 50, 30, 30);
  47.         lblUnidade.setVisible(false);
  48.  
  49.         //TEXTFIELDS
  50.         txtTemperatura = new TextField();
  51.         txtTemperatura.setBounds(180, 50, 200, 30);
  52.  
  53.         //BUTTON'S
  54.         btnCel = new Button("°C");
  55.         btnCel.setBounds(120, 130, 40, 40);
  56.         btnCel.setActionCommand("C");
  57.  
  58.         btnFa = new Button("°F");
  59.         btnFa.setBounds(220, 130, 40, 40);
  60.         btnFa.setActionCommand("F");
  61.  
  62.         btnKel = new Button("K");
  63.         btnKel.setBounds(320, 130, 40, 40);
  64.         btnKel.setActionCommand("K");
  65.  
  66.         //ADD'S
  67.         this.add(lblUnidade);
  68.         this.add(btnCel);
  69.         this.add(btnFa);
  70.         this.add(btnKel);
  71.         this.add(lblTemperatura);
  72.         this.add(lblTemp1);
  73.         this.add(lblTemp2);
  74.         this.add(txtTemperatura);
  75.     }
  76.  
  77.     public void exibeLabels(String unidade, double val1, double val2) {
  78.         lblTemp1.setVisible(true);
  79.         lblTemp2.setVisible(true);
  80.         lblUnidade.setVisible(true);
  81.         String v1 = null;
  82.         String v2 = null;
  83.         if (unidade.equals("ºC")) {
  84.             v1 = val1 + " ºF";
  85.             v2 = val2 + " K";
  86.         } else if (unidade.equals("K")) {
  87.             v1 = val1 + " ºC";
  88.             v2 = val2 + " ºF";
  89.         } else if (unidade.equals("ºF")) {
  90.             v1 = val1 + " ºC";
  91.             v2 = val2 + " K";
  92.         }
  93.         lblUnidade.setText(unidade);
  94.         lblTemp1.setText(v1);
  95.         lblTemp2.setText(v2);
  96.     }
  97.  
  98.     public void exibeErro() {
  99.         JOptionPane.showConfirmDialog(null, "Erro encontrado no valor inserido!", "Erro", JOptionPane.CLOSED_OPTION);
  100.     }
  101.  
  102.     public void setLblTemp1(Label lbltemp1) {
  103.         this.lblTemp1 = lbltemp1;
  104.     }
  105.  
  106.     public void setLblTemp2(Label lbltemp2) {
  107.         this.lblTemp2 = lbltemp2;
  108.     }
  109.  
  110.     public void setLblUnidade(Label lblunidade) {
  111.         this.lblUnidade = lblunidade;
  112.     }
  113.  
  114.     public String getTxtTemperatura() {
  115.         return txtTemperatura.getText();
  116.     }
  117.  
  118.     public void setActionListener(ActionListener app) {
  119.         btnCel.addActionListener(app);
  120.         btnKel.addActionListener(app);
  121.         btnFa.addActionListener(app);
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment