Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.util.regex.Pattern;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import java.io.*;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import javax.swing.*;
- public class Parqueo extends JFrame implements Serializable, ActionListener
- {
- String placa; // cedula de identidad
- int nit; // nombre
- String hi;
- String hs;
- String fechita;
- JLabel lb1,lb2;
- JTextField tf1;
- JButton b1,b2,b3;
- int pt=0;
- int min;
- public Parqueo()
- {
- super("Parqueo");
- setLayout(null);
- setVisible(true);
- lb1=new JLabel("DETALLE DE PAGO POR HORAS ESTACIONADAS");
- lb1.setBounds(195,10,270,30);
- lb2=new JLabel("Fecha de proceso");
- lb2.setBounds(320,40,200,30);
- Calendar fecha = new GregorianCalendar();
- int anio = fecha.get(Calendar.YEAR);
- int mes = fecha.get(Calendar.MONTH);
- int dia = fecha.get(Calendar.DAY_OF_MONTH);
- fechita=dia +"/" + (mes+1) + "/" + anio;
- tf1=new JTextField(fechita);
- tf1.setBounds(440,40,200,30);
- b1=new JButton("Adicionar nuevos registros");
- b1.setBounds(40,80,200,30);
- b2=new JButton("Reporte");
- b2.setBounds(240,80,200,30);
- b3=new JButton("Finalizar");
- b3.setBounds(440,80,200,30);
- add(lb1);
- add(lb2);
- add(tf1);
- add(b1);add(b2);add(b3);
- b1.addActionListener(this);
- b2.addActionListener(this);
- b3.addActionListener(this);
- }
- public Parqueo(String placa,int nit,String hi,String hs)
- { this.placa=placa;
- this.nit=nit;
- this.hi=hi;
- this.hs=hs;
- }
- public String get_placa() {
- return placa;
- }
- public int get_nit() {
- return nit;
- }
- public String get_hi() {
- return hi;
- }
- public String get_hs() {
- return hs;
- }
- public String get_fechita() {
- return fechita;
- }
- public String toString()
- { return get_placa()+ "," + get_nit() + "," + get_hi()+ ","+ get_hi()+","+get_fechita();
- }
- public int get_min(String hi, String hs){
- int h,m;
- String s = Pattern.quote(":");
- String pi[]= hi.split(s);
- int ih= Integer.parseInt(pi[0]);
- int im= Integer.parseInt(pi[1]);
- String s1 = Pattern.quote(":");
- String ps[]= hs.split(s1);
- int sh= Integer.parseInt(ps[0]);
- int sm= Integer.parseInt(ps[1]);
- if(ih<=sh) {
- h=sh-ih;
- }
- else {
- h=ih-sh;
- }
- if(im<=sm) {
- m=sm-im;
- }
- else {
- m=im-sm;
- }
- min=(h*60)-m;
- return min;
- }
- public int get_pago(String hi, String hs) {
- int pago,h,m,time;
- String s = Pattern.quote(":");
- String pi[]= hi.split(s);
- int ih= Integer.parseInt(pi[0]);
- int im= Integer.parseInt(pi[1]);
- String ps[]= hs.split(s);
- int sh= Integer.parseInt(ps[0]);
- int sm= Integer.parseInt(ps[1]);
- if(ih<=sh) {
- h=sh-ih;
- }
- else {
- h=ih-sh;
- }
- if(im<=sm) {
- m=sm-im;
- }
- else {
- m=im-sm;
- }
- time=h-(m/60);
- if(time<1) pago=5;
- if(time<3) pago=10;
- if(time<6) pago=15;
- else pago=20;
- return pago;
- }
- public int get_pt(int p) {
- pt+=p;
- return pt;
- }
- public int fech(String f) {
- String s = Pattern.quote(":");
- String parts[]= f.split(s);
- int h= Integer.parseInt(parts[0]);
- int m= Integer.parseInt(parts[1]);
- System.out.println(h+" "+m);
- if (h<=23){
- if (m<=59){
- return 1;
- }
- else {
- JOptionPane.showMessageDialog(null, "Introduzca de nuevo la fecha");
- return 0;
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "Introduzca de nuevo la fecha");
- return 0;
- }
- }
- public void write() throws IOException,ClassNotFoundException
- {
- try {
- int aux=0;
- String hi = null;
- String hs = null;
- File arch = new File("Vehiculos.bin");
- String placa=JOptionPane.showInputDialog("Placa del vehiculo:");
- String x1=JOptionPane.showInputDialog("NIT:");
- while(aux==0) {
- hi=JOptionPane.showInputDialog("Hora de ingreso:");
- aux=fech(hi);
- }
- aux=0;
- while(aux==0) {
- hs=JOptionPane.showInputDialog("Hora de salida:");
- aux=fech(hs);
- }
- int nit=Integer.parseInt(x1);
- Parqueo o=new Parqueo(placa,nit,hi,hs);
- if(arch.exists()){
- AppendableObjectOutputStream fs = new AppendableObjectOutputStream(new FileOutputStream(arch, true));
- fs.writeUnshared(o);
- fs.close();
- }
- else
- {
- ObjectOutputStream fs = new ObjectOutputStream(new FileOutputStream(arch, true));
- fs.writeUnshared(o);
- fs.close();
- }
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- public void read() throws IOException,ClassNotFoundException
- {
- try{
- String filename1="Vehiculos.bin";
- int p=0;
- FileInputStream fs2=new FileInputStream(filename1);
- ObjectInputStream fs1=new ObjectInputStream(fs2);
- String cad="PlacatHra. de IngresotHra. de SalidatTiempo en minutostPago Totaln";
- cad+="==============================================================================n";
- Parqueo objobrero;
- while (fs2.available()!=0)
- {
- objobrero = (Parqueo) fs1.readObject();
- cad+=objobrero.get_placa()+"t"+objobrero.get_hi()+"t"+objobrero.get_hs()+"n"+objobrero.get_min(get_hi(),get_hs()); /*+"t"+objobrero.get_pago(get_hi(),get_hs())+"n"
- p=get_pago(get_hi(),get_hs());
- get_pt(p);*/
- }
- cad+="===============================================================================n";
- cad+="Total general:t"+get_pt(p);
- JTextArea out=new JTextArea(10,50);
- out.setText(cad);
- JScrollPane barra=new JScrollPane(out);
- JOptionPane.showMessageDialog(null,barra);
- fs2.close();
- }
- catch(IOException e)
- {
- System.err.println("Error en el archivo"+e.getMessage());
- }
- }
- public void actionPerformed(ActionEvent event)
- {
- if(event.getSource()==b1)
- {
- try {
- write();
- } catch (IOException ex) {
- Logger.getLogger(ejer1.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(ejer1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if(event.getSource()==b2)
- {
- try {
- System.out.println("dddd");
- read();
- } catch (IOException ex) {
- Logger.getLogger(Parqueo.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(Parqueo.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if(event.getSource()==b3)
- { System.exit(0);
- dispose();
- }
- }
- public static void main(String args[]) throws IOException,ClassNotFoundException
- {
- Parqueo obj=new Parqueo();
- obj.setBounds(0,0,680,350);
- obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Add Comment
Please, Sign In to add comment