Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*:
- import java.awt.*;
- public class miUI extends JFrame {
- JTextField campo;
- JTextField bina;
- JTextField octa;
- JTextField hexa;
- public miUI(){
- super("Conversor");
- setLayout(new FlowLayout ());
- campo=new JTextField(" ",5);
- add(campo);
- bina=new JTextField(" ",5);
- add(bina);
- bina.setEditable(false);
- octa=new JTextField(" ",5);
- add(octa);
- octa.setEditable(false);
- hexa=new JTextField(" ",5);
- add(hexa);
- hexa.setEditable(false);
- handler h=new handler();
- campo.addActionListener(h);
- }
- private class handler implements ActionListener{
- public void actionPerformed (ActionEvent event){
- int i=0;
- String str="";
- if (event.getSource()==campo)
- try{
- i=Integer.parseInt(campo.getText());
- }
- catch(Exception e){
- System.out.println("Error");
- }
- str=Integer.toBinaryString(i);
- bina.setText(str);
- str=Integer.toOctalString(i);
- octa.setText(str);
- str=Integer.toHexString(i);
- hexa.setText(str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement