jueves, 13 de marzo de 2014

Calculo de ingresos


@SuppressWarnings("serial")
public class ejerc53 extends JFrame  implements ActionListener {
 JPanel panel;
JButton boton;
public static void main(String args[]) {
ejerc53 marco = new ejerc53();
marco.setSize(350, 250);
marco.dibujarGUI();
marco.setVisible(true);
}
private void dibujarGUI() {
setTitle("Calcula ingresos");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
Container ventana = getContentPane();
ventana.setLayout(new FlowLayout());
boton = new JButton("Solicita Ingreso anual y años trabajados");
ventana.add(boton);
boton.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
String sa = JOptionPane.showInputDialog(getParent(), "Sueldo anual ", "");
String at = JOptionPane.showInputDialog(getParent(), "Años trabajados ", "");
mostrarIngresos(sa,at);
}

private void mostrarIngresos(String sueldoAnual, String añosTrabajados) {
Integer sa = Integer.parseInt(sueldoAnual);
Integer at = Integer.parseInt(añosTrabajados);
Integer ingresos = sa*at;
JOptionPane.showMessageDialog(getParent(), "Los ingresos totales son " + ingresos.toString());
}


}

No hay comentarios:

Publicar un comentario