Advertisement
Kl43z

conv

Nov 30th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import javax.swing.*:
  2.  
  3. import java.awt.*;
  4.  
  5.  
  6.  
  7. public class miUI extends JFrame {
  8. JTextField campo;
  9. JTextField bina;
  10. JTextField octa;
  11. JTextField hexa;
  12.  
  13.  
  14. public miUI(){
  15. super("Conversor");
  16. setLayout(new FlowLayout ());
  17.  
  18. campo=new JTextField(" ",5);
  19. add(campo);
  20.  
  21. bina=new JTextField(" ",5);
  22. add(bina);
  23. bina.setEditable(false);
  24.  
  25. octa=new JTextField(" ",5);
  26. add(octa);
  27. octa.setEditable(false);
  28.  
  29. hexa=new JTextField(" ",5);
  30. add(hexa);
  31. hexa.setEditable(false);
  32.  
  33. handler h=new handler();
  34. campo.addActionListener(h);
  35.  
  36. }
  37.  
  38.  
  39. private class handler implements ActionListener{
  40. public void actionPerformed (ActionEvent event){
  41. int i=0;
  42. String str="";
  43.  
  44. if (event.getSource()==campo)
  45. try{
  46. i=Integer.parseInt(campo.getText());
  47. }
  48. catch(Exception e){
  49. System.out.println("Error");
  50. }
  51.  
  52. str=Integer.toBinaryString(i);
  53. bina.setText(str);
  54. str=Integer.toOctalString(i);
  55. octa.setText(str);
  56. str=Integer.toHexString(i);
  57. hexa.setText(str);
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement