Guest User

Untitled

a guest
Jun 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package guiexame20023;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class Conversor extends JFrame {
  8.  
  9. private JTextField caixatexto;
  10. private JLabel rotulo;
  11. JTextField caixatexto1;
  12.  
  13.  
  14. public Conversor(String titulo){
  15. super(titulo);
  16. setResizable(false);
  17.  
  18. Container c = getContentPane();
  19. JButton botao;
  20.  
  21. JPanel p1= new JPanel();
  22.  
  23. JPanel p11 = new JPanel();
  24. rotulo = new JLabel("Distância em Milhas");
  25. caixatexto = new JTextField(5);
  26. botao =new JButton("Converter");
  27. botao.addActionListener(new TrataEvento());
  28. p11.add(rotulo);
  29. p11.add(caixatexto);
  30. p11.add(botao);
  31. p1.add(p11);
  32. c.add(p1,BorderLayout.NORTH);
  33.  
  34. JPanel p2 = new JPanel();
  35.  
  36. JPanel p21 = new JPanel();
  37. caixatexto1 = new JTextField(22);
  38.  
  39. p21.add(caixatexto1);
  40. p2.add(p21);
  41. c.add(p2,BorderLayout.SOUTH);
  42.  
  43. pack();
  44. setVisible(true);
  45. }
  46.  
  47. class TrataEvento implements ActionListener{
  48. String x;
  49. public void actionPerformed(ActionEvent e) {
  50. if(e.getActionCommand().equals("Converter")){
  51. x = Conversao(Integer.parseInt(caixatexto.getText()));
  52. caixatexto1.setText(x);
  53. }
  54. }
  55. }
  56.  
  57. public String Conversao(int v){
  58. System.out.println(v);
  59. return v+" milhas igual a "+(v*1.6412)+" quilometros.";
  60. }
  61. }
Add Comment
Please, Sign In to add comment