Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Gui13 extends JFrame{
- JLabel l1;
- JButton b1,b2;
- JTextField cantidad;
- public Gui13(){
- super("Conversor Euros-pesetas");
- setLayout(new FlowLayout());
- b1=new JButton("A euros");
- b2=new JButton("A pesetas");
- cantidad = new JTextField(10);
- l1=new JLabel("Texto");
- add(l1);
- add(cantidad);
- add(b1);
- add(b2);
- b1.addActionListener(new OyenteBoton());
- b2.addActionListener(new OyenteBoton());
- b1.setActionCommand("E");
- b2.setActionCommand("P");
- setSize(400,100);
- setVisible(true);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- public static void main(String[] args) {
- Gui13 ventana = new Gui13();
- }
- class OyenteBoton implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent e) {
- Float f = new Float(cantidad.getText());
- float valor = f.floatValue();
- String s = (String) e.getActionCommand();
- if (s.equals("E")){
- valor = (float) (valor/166.321);
- } else if (s.equals("P")){
- valor = (float) (valor*166.321);
- }
- cantidad.setText(Float.toString(valor));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement