Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. public class Gui13  extends JFrame{
  2.     JLabel l1;
  3.     JButton b1,b2;
  4.     JTextField cantidad;
  5.    
  6.     public Gui13(){
  7.         super("Conversor Euros-pesetas");
  8.         setLayout(new FlowLayout());
  9.        
  10.         b1=new JButton("A euros");
  11.         b2=new JButton("A pesetas");
  12.         cantidad = new JTextField(10);
  13.         l1=new JLabel("Texto");
  14.         add(l1);
  15.         add(cantidad);
  16.         add(b1);
  17.         add(b2);
  18.        
  19.         b1.addActionListener(new OyenteBoton());
  20.         b2.addActionListener(new OyenteBoton());
  21.        
  22.         b1.setActionCommand("E");
  23.         b2.setActionCommand("P");
  24.        
  25.         setSize(400,100);
  26.         setVisible(true);
  27.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  28.     }
  29.  
  30.        
  31.     public static void main(String[] args) {
  32.         Gui13 ventana = new Gui13();
  33.        
  34.     }
  35.    
  36.     class OyenteBoton implements ActionListener{
  37.         @Override
  38.         public void actionPerformed(ActionEvent e) {
  39.            Float f = new Float(cantidad.getText());
  40.            float valor = f.floatValue();
  41.            
  42.            String s = (String) e.getActionCommand();
  43.            
  44.            if (s.equals("E")){
  45.                valor = (float) (valor/166.321);
  46.            } else if (s.equals("P")){
  47.                valor = (float) (valor*166.321);
  48.            }
  49.            cantidad.setText(Float.toString(valor));
  50.         }
  51.     }
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement