Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guiexame20023;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Conversor extends JFrame {
- private JTextField caixatexto;
- private JLabel rotulo;
- JTextField caixatexto1;
- public Conversor(String titulo){
- super(titulo);
- setResizable(false);
- Container c = getContentPane();
- JButton botao;
- JPanel p1= new JPanel();
- JPanel p11 = new JPanel();
- rotulo = new JLabel("Distância em Milhas");
- caixatexto = new JTextField(5);
- botao =new JButton("Converter");
- botao.addActionListener(new TrataEvento());
- p11.add(rotulo);
- p11.add(caixatexto);
- p11.add(botao);
- p1.add(p11);
- c.add(p1,BorderLayout.NORTH);
- JPanel p2 = new JPanel();
- JPanel p21 = new JPanel();
- caixatexto1 = new JTextField(22);
- p21.add(caixatexto1);
- p2.add(p21);
- c.add(p2,BorderLayout.SOUTH);
- pack();
- setVisible(true);
- }
- class TrataEvento implements ActionListener{
- String x;
- public void actionPerformed(ActionEvent e) {
- if(e.getActionCommand().equals("Converter")){
- x = Conversao(Integer.parseInt(caixatexto.getText()));
- caixatexto1.setText(x);
- }
- }
- }
- public String Conversao(int v){
- System.out.println(v);
- return v+" milhas igual a "+(v*1.6412)+" quilometros.";
- }
- }
Add Comment
Please, Sign In to add comment