Acá el Código
//La Clase Sistema
import java.awt.event.*;
import javax.swing.*;
public class Sistema extends JFrame{
ImageIcon img[]={new ImageIcon("Metro.jpg"),new ImageIcon("Figura.jpg"),new ImageIcon("Comprar.jpg"),new ImageIcon("Recarga.jpg"),new ImageIcon("Saldo.jpg")};
JLabel lblMaquina=new JLabel(img[0]);
JButton btnComprar=new JButton(img[2]);
JButton btnRecarga=new JButton(img[3]);
JButton btnSaldo=new JButton(img[4]);
public Sistema(){
Panel p=new Panel();
setTitle("Sistema");
setSize(800,650);
p.setLocation(100, 50);
p.setLayout(null);
p.add(lblMaquina); lblMaquina.setBounds(250,50,330,72);
p.add(btnComprar); btnComprar.setBounds(200,150,400,100);
p.add(btnRecarga); btnRecarga.setBounds(200,300,400,100);
p.add(btnSaldo); btnSaldo.setBounds(200,450,400,100);
Container c=getContentPane();
c.add(p);
btnComprar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent cp){
Comprar c=new Comprar();
c.setLocation(100, 50);
c.setVisible(true);
dispose();
}
});
btnRecarga.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Rg){
Recarga r=new Recarga();
r.setLocation(100, 50);
r.setVisible(true);
dispose();
}
});
btnSaldo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent sl){
Saldo s=new Saldo();
s.setLocation(100, 50);
s.setVisible(true);
dispose();
}
});
}
}
//La Clase Comprar
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.*;
public class Comprar extends JFrame{
ImageIcon img[]={new ImageIcon("Cancelar.jpg"),new ImageIcon("Aceptar.jpg"),new ImageIcon("Signo.jpg")};
JButton btnCancelar=new JButton(img[0]);
JButton btnContinuar=new JButton(img[1]);
JLabel lblCosto=new JLabel("Costo");
JLabel lblCos=new JLabel("$10.00");
JLabel lblPasaje=new JLabel("Pasaje");
JLabel lblPas=new JLabel("$5.00");
JLabel lblCantidad=new JLabel("Cantidad");
JLabel lblpesos=new JLabel("$");
JLabel lblpes=new JLabel("0");
JLabel lblDinero=new JLabel("Introdusca Dinero");
JButton Introduce=new JButton(img[2]);
public Comprar(){
Panel p=new Panel();
setTitle("Comprar Targeta");
setSize(800,650);
p.setLayout(null);
lblCosto.setFont(new Font("Arial", Font.BOLD,30));
p.add(lblCosto); lblCosto.setBounds(50,100,100,50);
lblCos.setFont(new Font("Arial", Font.BOLD,20));
p.add(lblCos); lblCos.setBounds(50,140,100,50);
lblPasaje.setFont(new Font("Arial", Font.BOLD,30));
p.add(lblPasaje); lblPasaje.setBounds(50,200,100,50);
lblPas.setFont(new Font("Arial", Font.BOLD,20));
p.add(lblPas); lblPas.setBounds(50,240,100,50);
p.add(btnCancelar); btnCancelar.setBounds(50,500,100,100);
p.add(btnContinuar); btnContinuar.setBounds(500,500,100,100);
lblCantidad.setFont(new Font("Arial", Font.BOLD,40));
p.add(lblCantidad); lblCantidad.setBounds(350,140,250,50);
lblpesos.setFont(new Font("Arial", Font.BOLD,40));
p.add(lblpesos); lblpesos.setBounds(350,190,250,50);
lblpes.setFont(new Font("Arial", Font.BOLD,40));
p.add(lblpes); lblpes.setBounds(380,190,250,50);
p.add(lblDinero); lblDinero.setBounds(650,10,150,30);
p.add(Introduce); Introduce.setBounds(650,50,100,100);
Container c=getContentPane();
c.add(p);
btnContinuar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent con){
Procesando p=new Procesando(lblpes.getText());
p.setVisible(true);
dispose();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:Database"," "," ");
PreparedStatement st=c.prepareStatement("Insert into Tabla1(Saldo) values(?)");
st.setInt(1,Integer.parseInt(lblpes.getText()));
st.executeUpdate();
lblpes.setText(" ");
}catch(Exception er){
JOptionPane.showMessageDialog(null,"Error" + er);
}
}
});
btnCancelar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent can){
Sistema s=new Sistema();
s.setVisible(true);
dispose();
}
});
Introduce.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent pes){
int Costo=10;
String Cantidad = JOptionPane.showInputDialog("Cantidad:");
int res=Integer.parseInt(Cantidad)-Costo;
lblpes.setText(String.valueOf(res));
}
});
}
}
No hay comentarios:
Publicar un comentario