Você está na página 1de 5

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ventanas;
import com.barcodelib.barcode.QRCode;
//import java.awt.ComponentOrientation;
import java.awt.Desktop;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.JOptionPane;
//import javax.swing.ImageIcon;
/**
*
*@author NAVEGATI
*/
public class ven extends javax.swing.JFrame {
/**
* Creates new form ven
*/
int udm=0;//medida en pixeles
int resol= 72;
float mi=0.000f;//Margen izq
float md=0.000f; //Margen derecho
float ms=0.000f;// Margen Superio
float min=0.00f; //Margen Inferior
int rot= 0; //Grado de rotacion del codigo
float tam= 5.000f; //Tamano de la imagen

//ImageIcon Imagen[]= new ImageIcon[1];
public ven() {
initComponents();
//ventana en el medio

//Imagen[0]= new ImageIcon(getClass().getResource(archiv));

this.setLocationRelativeTo(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*@return
*/



@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextField1 = new javax.swing.JTextPane();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("GENCOD by Roberto Bustamante");
setIconImage(getIconImage());
setResizable(false);
jButton1.setText("Generar");
jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextField1.addHierarchyBoundsListener(new java.awt.event.HierarchyBound
sListener() {
public void ancestorMoved(java.awt.event.HierarchyEvent evt) {
hola(evt);
}
public void ancestorResized(java.awt.event.HierarchyEvent evt) {
}
});
jScrollPane1.setViewportView(jTextField1);
jTextField1.getAccessibleContext().setAccessibleName("");
jLabel1.setText("GENERADOR DE CODIGO QR");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(122, 122, 122)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREF
ERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(163, 163, 163)
.addComponent(jButton1)))
.addContainerGap(58, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createS
equentialGroup()
.addGap(33, 33, 33)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SI
ZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(76, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
@Override
public Image getIconImage(){
Image retValue=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResourc
e("iconos/roberto.png"));
return retValue;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
String texto= jTextField1.getText();
if (texto.equals("")==false){
//bloque de verdad

try {
QRCode cod =new QRCode(); // se crea el objeto cod
//Se envia a la informacion del text box a la variable

cod.setData(texto);// se asigna con el metodo al objeto el texto
cod.setDataMode(QRCode.MODE_BYTE);//tipo de texto a codificar ; ModeNume
ric, Auto , custumer etc
cod.setUOM(udm);
cod.setLeftMargin(mi);
cod.setResolution(resol);
cod.setRightMargin(md);
cod.setTopMargin(ms);
cod.setBottomMargin(min);
cod.setRotate(rot);
cod.setModuleSize(tam);
String archiv= System.getProperty("user.home")+"/GENCOD.gif";

cod.renderBarcode(archiv); //enviamos el archivo
//JOptionPane.showMessageDialog(null,archiv,"GENCOD",1);
// icon.SetIcon(imagen[1]);

Desktop d = Desktop.getDesktop();
d.open(new File(archiv) );


} catch(Exception e) { }



}
else{

JOptionPane.showMessageDialog(null,"introduzca texto","GENCOD",1);

}





}
private void hola(java.awt.event.HierarchyEvent evt) {
// TODO add your handling code here:
}



/**
*@param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccess
Exception | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccess
Exception | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ven.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ven().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane jTextField1;
// End of variables declaration
}