Cómo escribir una aplicación de cajero automático sencilla usando JAVA
importar javax.swing.*;
importar java.awt.event.*;
la clase pública SimAtm extiende JFrame implementa java.awt.event.ActionListener {
Private static final long serialVersionUID = 1L;
JButton privado[] peros = new JButton[4]
string privado [] tils = new String; [] {"Depósito", "Retiro", "Consulta", "Salir"};
private int money = 0
private JLabel lab = new JLabel(); /p>
public SimAtm() {
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this. setBounds(400, 250, 420, 200);
int w = 100;
int h = 30;
lab.setForeground(java.awt. Color.rojo);
lab.setBounds(0, 50, 400, 50;
for(int i = 0; i lt; 4; i) {
peros[i] = new JButton(tils[i]);
peros[i].addActionListener(this
peros[i].setBounds(i); * w, 0, w, h);
this.add(peros[i]);
}
this.add(lab);
this.setVisible(true);
}
public static void main(String[] args) {
new SimAtm() ;
}
public void actionPerformed(ActionEvent e) {
Objeto op = e.getSource();
if( op == buts[0]){
String is = JOptionPane.showInputDialog(null, "Ingrese el monto del depósito:");
if(is != null amp; amp; is .matches("\\d ")) {
int input = Integer.parseInt(is);
dinero = input
lab.setText( "Ya depositaste "entrada"
elemento");
}
} else if(op == buts[1] ){
String is = JOptionPane.showInputDialog(null, "Entrada Monto del retiro: ");
if(is != null amp; amp; is.matches("\\d ")) {
int input = Integer.parseInt(is );
entrada = entrada gt; = dinero ? dinero : entrada
dinero -= entrada
lab.setText("Lo has tomado" ingrese "yuan");
}
} else if(op == buts[2]) {
JOptionPane.showMessageDialog(null, "Saldo actual es: " dinero);
lab.setText("Saldo actual: " dinero);
} else{
System.exit(0);
}
}
}