miércoles, 22 de noviembre de 2023

Imprimir con Imagen de Barcode en Java Netbeans

Se tiene la imagen barcode1.gif que se agrega a la impresion en el metodo print.

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.*;
import javax.swing.ImageIcon;
import java.awt.Image;

public class imprimir2 implements Printable {

    public static void main(String[] args) {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(new imprimir2());
        //job.setPrintable(this);
        boolean doPrint = job.printDialog();
        System.out.println(doPrint);
        if (doPrint) {
            try {
                job.print();
            } catch (PrinterException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public int print(Graphics g, PageFormat pf, int page) throws         PrinterException {
        if (page > 0) {
             return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D) g;
Image img1;
ImageIcon icon = new ImageIcon("barcode1.gif");
        img1 = icon.getImage();
        g.drawString("minuvaHard10 corp.", 100, 100);
        g.drawString("Simulacion de Ticket", 100, 130);
  g.drawImage(img1, 200, 170,null);
        return PAGE_EXISTS;
    }
}
e-mail: minuvasoft10@gmail.com    Miguel Nunez Programador de Proyectos Software en Java.




jueves, 2 de noviembre de 2023

Animacion de Paloma Volando con JavaScript

Ejemplo aqui

Tenemos las siguientes imagenes secuenciales



paloma1.png, paloma2.png... paloma9.png

<!DOCTYPE html>

<html>

<head>
<style>
#home {
  width: 580px;
  height: 215px;
}
</style>
</head>
<body onload="setInterval(anima,400)">
<img id="next" src="paloma1.png" width="160px">
<script>
  var x=0;
  function anima() {
    x = x + 1;
    var cad="";
    cad = "paloma" + x + ".png"; 
    document.getElementById("next").src = cad;
    if (x>8) { x=0; }
    
  }
</script>
</body>
</html>


miércoles, 18 de octubre de 2023

Simulacion de Factura con Java Netbeans Jtable Agregar Eliminar Imprimir + codigo fuente

Se imprime mediante un documento pdf, uno tamano carta y otro tamano ticket. Se debe incluir la libreria itextpdf.5.4.3.jar en libraries del proyecto.





package pktFactu;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import static com.itextpdf.text.Element.ALIGN_RIGHT;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Desktop;
import java.awt.Font;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class frmFactu extends javax.swing.JFrame {
DefaultTableModel model=new DefaultTableModel();
    public frmFactu() {
        initComponents();
        cargaCli();
        tblPro.setModel(model);
        String titu[]={"Producto","Precio_Uni","Cantidad","Importe"};
        model.setColumnIdentifiers(titu);
        tblPro.getColumnModel().getColumn(0).setPreferredWidth(200);
    }
private void cargaCli(){
    cmbCli.addItem("[Seleccionar]");
    cmbCli.addItem("Miguel Nunez Varillas");
    cmbCli.addItem("Gladis Zegarra Cordova");
    cmbCli.addItem("Rosa Castro Espinoza");
    cmbCli.addItem("Ronaldo Altamirez");
    cmbCli.addItem("Julio Ortiz Yason");
    cmbCli.addItem("Liliana Vergaray Returto");
    cmbCli.addItem("Teofilo Cubillas Nieto");
}
 private void cmbCliItemStateChanged(java.awt.event.ItemEvent evt) {      String Ruc=""; 
        if (cmbCli.getSelectedIndex()>0){
             switch (cmbCli.getSelectedIndex()) {
                 case 1:Ruc="11235689654";break;
                 case 2:Ruc="44895623147";break;
                 case 3:Ruc="33226688964";break;
                 case 4:Ruc="77553311992";break;
                 default : Ruc="33366689641";
             }
             txtRuc.setText(Ruc);
         }
    }                                       

 private void cmbProItemStateChanged(java.awt.event.ItemEvent evt) {      String pre="";
        if (cmbPro.getSelectedIndex()>0){
            switch (cmbPro.getSelectedIndex()) {
                case 1:pre="400";break;
                case 2:pre="460";break;
                case 3:pre="550";break;
                case 4:pre="600";break;
                case 5:pre="300";break;
                case 6:pre="40";break;
                case 7:pre="68";break;
                default : pre="120";
            }
            txtPre.setText(pre);
            txtCan.setText("1");
        }
    }                                       
private double redondear(double num){
    return Math.rint(num*100)/100;
}
private void calTot(){
    double S=0,igv,tot;
    for(int i=0;i<tblPro.getRowCount();i++){
        S=S+Double.parseDouble(model.getValueAt(i, 3).toString());
    }
    S=redondear(S);
    lblSub.setText(String.valueOf(S));
    igv=0.09*S;
    igv=redondear(igv);
    tot=S*1.09;
    tot=redondear(tot);
    lblIGV.setText(String.valueOf(igv));
    lblTotal.setText(String.valueOf(tot));
}
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {      String rowData[]=new String[4];
    rowData[0]=cmbPro.getSelectedItem().toString();
    rowData[1]=txtPre.getText();
    rowData[2]=txtCan.getText();
    Double imp=Double.parseDouble(rowData[1])*Double.parseDouble(rowData[2]);
    imp=redondear(imp);
    rowData[3]=imp.toString();
    model.addRow(rowData);
    calTot();
}                                      
private void eliminar(){
    int fil;
    if (model.getRowCount()>0){
        if (tblPro.getSelectedRow()!=-1){
            fil=tblPro.getSelectedRow();
            model.removeRow(fil);
            calTot();
        }else{
          JOptionPane.showMessageDialog(null, "Seleccione Una Fila");
        }
    }else{ JOptionPane.showMessageDialog(null, "No hay Filas en la         Tabla");}
}

private void btnEliActionPerformed(java.awt.event.ActionEvent evt) {      String cad="";
    cad = JOptionPane.showInputDialog("Password Manager");
    if (cad.contentEquals("1234")) {
        eliminar();
    } else {
        JOptionPane.showMessageDialog(null, "PassWord Erroneo");
    }
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {                                         
    imprimir();
}                                        
private void imprimir2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
    imp2();
}                                         
private void imp2() {
try{
    OutputStream file = new FileOutputStream(new File("Test5.pdf"));
    Document document = new Document();
    PdfWriter.getInstance(document, file);
    Rectangle one = new Rectangle(288,400);
    document.setPageSize(one);
    document.setMargins(2, 2, 2, 2);
    document.open();
    Paragraph p=new Paragraph("MinuvaHard10 Market",
    FontFactory.getFont("arial",14,Font.ITALIC,BaseColor.BLUE)); 
    p.setAlignment(Element.ALIGN_CENTER);
    document.add(p);
    document.add(new Paragraph("Comprobante de Pago"));
    PdfPTable tabla = new PdfPTable(4);
    float[] medida = {1.95f, 0.5f,0.5f,0.55f};
    tabla.addCell(new             Paragraph("hello",FontFactory.getFont("arial",12)));
         tabla.setWidths(medida);
        int n=model.getRowCount();
         int i = 0;
         tabla.getDefaultCell().setBorder(0);
    while (i<n){
      tabla.addCell(new Paragraph(model.getValueAt(i, 0).toString(), FontFactory.getFont("arial",10)));
      tabla.addCell(new Paragraph(model.getValueAt(i, 1).toString(),FontFactory.getFont("arial",10)));
      tabla.addCell(new Paragraph(model.getValueAt(i, 2).toString(),FontFactory.getFont("arial",10)));
      tabla.addCell(new Paragraph(model.getValueAt(i, 3).toString(),FontFactory.getFont("arial",10)));
             i++;
    }
  document.add(tabla);
  Paragraph st=new Paragraph("SubTotal "+lblSub.getText(),
FontFactory.getFont("arial", 
10,                           
Font.ITALIC,               
BaseColor.BLUE)); 
         st.setAlignment(Element.ALIGN_RIGHT);
         document.add(st);
         document.close();
         file.close();
     }catch(Exception e){
         JOptionPane.showMessageDialog(null,"Error:"+e.getMessage());
     }
    try {
            File file = new File("Test5.pdf");
            Desktop.getDesktop().open(file);
    } catch(Exception e) {
            e.printStackTrace();
    }
    }
private void imprimir() {
   try{
        OutputStream file = new FileOutputStream(new                 File("Test4.pdf"));
        Document document = new Document();
        PdfWriter.getInstance(document, file);
        document.setPageSize(one);
        document.open();
        PdfPTable tabla = new PdfPTable(4);
        Paragraph p=new Paragraph("Factura",
FontFactory.getFont("arial",  
14,                           
Font.ITALIC,             
BaseColor.BLUE)); 
            p.setAlignment(Element.ALIGN_CENTER);
            document.add(p);
            document.add(new Paragraph(" "));
            document.add(new Paragraph("Cliente "+cmbCli.getSelectedItem().toString()));
            document.add(new Paragraph("RUC "+txtRuc.getText()));
            float[] medidaCeldas = {1.5f, 1.25f, 0.55f, 0.5f};
          tabla.addCell(new Paragraph("hello",FontFactory.getFont("arial",12)));
            tabla.setWidths(medidaCeldas);
            tabla.addCell(new Paragraph("Producto",FontFactory.getFont("arial",12)));
            tabla.addCell(new Paragraph("Precio Uni",FontFactory.getFont("arial",12)));
            tabla.addCell(new Paragraph("Cantidad",FontFactory.getFont("arial",12)));
            tabla.addCell(new Paragraph("Importe",FontFactory.getFont("arial",12)));
         int n=model.getRowCount();
         int i = 0;
         while (i<n){
             tabla.addCell(new Paragraph(model.getValueAt(i, 0).toString(), FontFactory.getFont("arial",10)));
             tabla.addCell(new Paragraph(model.getValueAt(i, 1).toString(),FontFactory.getFont("arial",10)));
             tabla.addCell(new Paragraph(model.getValueAt(i, 2).toString(),FontFactory.getFont("arial",10)));
             tabla.addCell(new Paragraph(model.getValueAt(i, 3).toString(),FontFactory.getFont("arial",10)));
             i++;
         }
         document.add(tabla);
         String cad2 = "-----------------------------------";
         document.add(new Paragraph(cad2+"SubTotal "+lblSub.getText()));
         document.add(new Paragraph("Tax "+lblIGV.getText()));
         document.add(new Paragraph("Total "+lblTotal.getText()));
         document.close();
         file.close();
        }catch(Exception e){
         JOptionPane.showMessageDialog(null,"Error:"+e.getMessage());
        }
        try {
            File file = new File("Test4.pdf");
            Desktop.getDesktop().open(file);
        } catch(Exception e) {
            e.printStackTrace();
        }

    }
download aqui    
e-mail : minuvasoft10@gmail.com




                               

  

            


 

sábado, 9 de septiembre de 2023

Tabla con Python y PyQt5

 

import sys  

from PyQt5.QtWidgets import *  

#Main Window  

class App(QWidget):  

    def __init__(self):  

        super().__init__()  

        # Setting the title  

        self.title = 'minuvaHard10 PyQt5 Table'  

        # Setting the Position  

        self.left = 0  

        self.top = 0  

        self.width = 400  

        self.height = 250  

        self.setWindowTitle(self.title)  

        self.setGeometry(self.left+200, self.top+200, self.width, self.height+200)  

        self.tableNew = QTableWidget(self)  

  # Giving the count for the Row   

        self.tableNew.setRowCount(4)  

   # Giving the count for the Column  

        self.tableNew.setColumnCount(2)  

  self.tableNew.setItem(0, 0, QTableWidgetItem("Banana 5u"))  

        self.tableNew.setItem(0, 1, QTableWidgetItem("1.55"))  

        self.tableNew.setItem(1, 0, QTableWidgetItem("Cucumber green"))  

        self.tableNew.setItem(1, 1, QTableWidgetItem("1.55"))  

        self.tableNew.move(20,120)

        self.tableNew.resize(280, 200)

        self.tableNew.setHorizontalHeaderLabels(["Producto", "Precio Uni"])  # Set the table headers

if __name__ == '__main__':  

   # creating the pyqt5 application      

    base = QApplication(sys.argv)  

  # creating an instance of the created Window  

    window = App()  

  # starting the application   

    sys.exit(base.exec_()) 

minuvasoft10@gmail.com - Programacion de projectos software en java netbeans, python, mysql, visual C#.

jueves, 10 de agosto de 2023

Java Netbeans JTable Agregar Filas y Eliminar

Agregar el Jtable de la paleta

Ponerle nombre tblPro haciendo click derecho sobre la tabla y escogiendo change variable name

import javax.swing.table.DefaultTableModel;
public class frmVentas extends javax.swing.JFrame {
    DefaultTableModel model = new DefaultTableModel();
    public frmVentas() {
        initComponents();
        tblPro.setModel(model);   // Establece el modelo a la tabla
        model.addColumn("Bar Code");
        model.addColumn("Nombre");  // Agrega 3 columnas
        model.addColumn("Precio");
        String data[]= new String[3];
        data[0]="028282"; data[1]="Milk Altadena !G";
        data[2]="2.55";
        tblPro.setForeground(Color.BLUE);  // Establece color de letra azul
        tblPro.getColumnModel().getColumn(1).setPreferredWidth(140); // Establece ancho
        tblPro.getColumnModel().getColumn(2).setPreferredWidth(8);
        model.addRow(data);  // Agrega una fila con los valores de data.
    }

Projectos de Programacion a minuvasoft10@gmail.com Miguel Nunez
Web Sites, Programacion Java Desktop, Python.







 

lunes, 3 de abril de 2023

E-File Software para Impuestos

 E-File es un software para pagar impuestos del IRS(internal revenue service).

Usa e-file si ganas menos que $73 000, si tienes un negocio o autoempleado.

e-file es gratuito.



sábado, 4 de marzo de 2023

Tarjeta AGP

Accelerated Graphics Port o AGP (en español "Puerto de gráfico acelerado") es una tarjeta de video o grafica, tiene una especificación de bus que proporciona una conexión directa entre el adaptador de gráficos y la memoria. Es un puerto (puesto que solo se puede conectar un dispositivo, mientras que en el bus se pueden conectar varios) desarrollado por Intel en 1996 como solución a los cuellos de botella que se producían en las tarjetas gráficas que usaban el bus PCI.2​ El diseño parte de las especificaciones del PCI 2.1.
con conector VGA
minuvasoft10@gmail.com




Conectar a MySql con Java Netbeans mediante un Formulario

 Tener agregado en libraries el conector mysql. clase coneBD.java package pktForm12; import java.sql.*; import javax.swing.JOptionPane; publ...