Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package conversor;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.Label;
- import java.awt.Button;
- import java.awt.TextField;
- import java.awt.event.ActionListener;
- import javax.swing.JOptionPane;
- public class Interface extends Frame {
- private Label lblTemp1;
- private Label lblTemp2;
- private Label lblUnidade;
- private TextField txtTemperatura;
- private Button btnCel;
- private Button btnFa;
- private Button btnKel;
- public Interface() {
- //DEFINIÇÕES DA JANELA
- this.setLayout(null);
- this.setResizable(false);
- this.setUndecorated(false);
- this.setVisible(true);
- this.setBounds(100, 10, 450, 300);
- this.setBackground(Color.WHITE);
- this.setTitle("CONVERSOR");
- //LABEL'S
- Label lblTemperatura = new Label("Temperatura:");
- lblTemperatura.setBounds(50, 50, 120, 30);
- lblTemp1 = new Label("");
- lblTemp1.setBounds(90, 220, 150, 30);
- lblTemp1.setVisible(false);
- lblTemp2 = new Label("");
- lblTemp2.setBounds(250, 220, 150, 30);
- lblTemp2.setVisible(false);
- lblUnidade = new Label("");
- lblUnidade.setBounds(390, 50, 30, 30);
- lblUnidade.setVisible(false);
- //TEXTFIELDS
- txtTemperatura = new TextField();
- txtTemperatura.setBounds(180, 50, 200, 30);
- //BUTTON'S
- btnCel = new Button("°C");
- btnCel.setBounds(120, 130, 40, 40);
- btnCel.setActionCommand("C");
- btnFa = new Button("°F");
- btnFa.setBounds(220, 130, 40, 40);
- btnFa.setActionCommand("F");
- btnKel = new Button("K");
- btnKel.setBounds(320, 130, 40, 40);
- btnKel.setActionCommand("K");
- //ADD'S
- this.add(lblUnidade);
- this.add(btnCel);
- this.add(btnFa);
- this.add(btnKel);
- this.add(lblTemperatura);
- this.add(lblTemp1);
- this.add(lblTemp2);
- this.add(txtTemperatura);
- }
- public void exibeLabels(String unidade, double val1, double val2) {
- lblTemp1.setVisible(true);
- lblTemp2.setVisible(true);
- lblUnidade.setVisible(true);
- String v1 = null;
- String v2 = null;
- if (unidade.equals("ºC")) {
- v1 = val1 + " ºF";
- v2 = val2 + " K";
- } else if (unidade.equals("K")) {
- v1 = val1 + " ºC";
- v2 = val2 + " ºF";
- } else if (unidade.equals("ºF")) {
- v1 = val1 + " ºC";
- v2 = val2 + " K";
- }
- lblUnidade.setText(unidade);
- lblTemp1.setText(v1);
- lblTemp2.setText(v2);
- }
- public void exibeErro() {
- JOptionPane.showConfirmDialog(null, "Erro encontrado no valor inserido!", "Erro", JOptionPane.CLOSED_OPTION);
- }
- public void setLblTemp1(Label lbltemp1) {
- this.lblTemp1 = lbltemp1;
- }
- public void setLblTemp2(Label lbltemp2) {
- this.lblTemp2 = lbltemp2;
- }
- public void setLblUnidade(Label lblunidade) {
- this.lblUnidade = lblunidade;
- }
- public String getTxtTemperatura() {
- return txtTemperatura.getText();
- }
- public void setActionListener(ActionListener app) {
- btnCel.addActionListener(app);
- btnKel.addActionListener(app);
- btnFa.addActionListener(app);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment