Vac_4Ventana

Vac_4Ventana

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

 

@SuppressWarnings("serial")

public class Vac_4Ventana extends JFrame implements ActionListener{

               

                private JButton boton;

                private JLabel etiquetaInstruccion,etiqueta1,etiqueta2,etiqueta3;

                private JTextField primerNum,segundoNum,tercerNum,campoResultado;

               

                public static void main(String[] args) {

                               Vac_4Ventana marco = new Vac_4Ventana();

                               marco.setSize(225,220);

                               marco.crearGUI();

                               marco.setVisible(true);

                }

                private void crearGUI(){

                               setDefaultCloseOperation(EXIT_ON_CLOSE);

                               Container ventana = getContentPane();

                               ventana.setLayout(new FlowLayout());

                              

                               etiquetaInstruccion = new JLabel("Introduzca 3 numeros diferentes enteros\n");

                               etiquetaInstruccion.setFont(new Font(null,Font.PLAIN,11));

                               ventana.add(etiquetaInstruccion);

                              

                               etiqueta1 = new JLabel("1er numero\n");

                               etiqueta1.setFont(new Font(null,Font.PLAIN,10));

                               ventana.add(etiqueta1);

                              

                               primerNum = new JTextField(10);

                               primerNum.setFont(new Font(null,Font.ITALIC,12));

                               ventana.add(primerNum);

                              

                               etiqueta2 = new JLabel("2do numero\n");

                               etiqueta2.setFont(new Font(null,Font.PLAIN,10));

                               ventana.add(etiqueta2);

                              

                               segundoNum = new JTextField(10);

                               segundoNum.setFont(new Font(null,Font.ITALIC,12));

                               ventana.add(segundoNum);

                              

                               etiqueta3 = new JLabel("3er numero\n");

                               etiqueta3.setFont(new Font(null,Font.PLAIN,10));

                               ventana.add(etiqueta3);

                              

                               tercerNum = new JTextField(10);

                               tercerNum.setFont(new Font(null,Font.ITALIC,12));

                               ventana.add(tercerNum);

                              

                               boton = new JButton("Mostrar");

                               boton.setFont(new Font(null,Font.BOLD,15));

                               ventana.add(boton);

                               boton.addActionListener(this);

                              

                               campoResultado = new JTextField(19);

                               campoResultado.setFont(new Font(null,Font.ITALIC,11));

                               ventana.add(campoResultado);

                }

                @Override

                public void actionPerformed(ActionEvent event){

                               int a,b,c;

                               String aString,bString,cString;

                               aString = primerNum.getText();

                               a = Integer.parseInt(aString);

                               bString = segundoNum.getText();

                               b = Integer.parseInt(bString);

                               cString = tercerNum.getText();

                               c = Integer.parseInt(cString);

                               if(a>b && a>c)

                                               campoResultado.setText("El 1er numero es mayor: " + a);

                               else{

                                               if(b>a && b>c){

                                                               campoResultado.setText("El 2do numero es mayor: " + b);

                                               }

                                               else{

                                                               campoResultado.setText("El 3er numero es mayor: " + c);

                                               }

                               }

                }

}