Javaweb gerando QR code

0 respostas
mattheus1

Olá amigos java, estou começando no fantástico mundo dos códigos e estou criando uma aplicação web que gera QRCode porém estava acompanhando um tutorial https://www.youtube.com/watch?v=TV4RcnBY_SU e fiz tudo igual ao professor e não deu certo, não sei lidar com erros java ainda mas alguém pode me dar uma força nesse erro em específico? att
package com.myapp.struts;

import java.io.ByteArrayOutputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;

import net.glxn.qrgen.QRCode;

import net.glxn.qrgen.image.ImageType;

/**
*

  • @author Ana
    */
    public class QRCodeSwing extends javax.swing.JFrame {

    /**

    • Creates new form QRCode
      */
      public QRCodeSwing() {
      initComponents();
      }

    /**

    • 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.
      
      */
      
      @SuppressWarnings(unchecked)
      
      // 
      
      private void initComponents() {
      
      jPanel1 = new javax.swing.JPanel();
      
      jScrollPane1 = new javax.swing.JScrollPane();
      
      textoParaQRCode = new javax.swing.JTextArea();
      
      btnGerar = new javax.swing.JButton();
      
      btnLimpar = new javax.swing.JButton();
      
      jLabel1 = new javax.swing.JLabel();
      

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      getContentPane().setLayout(null);

      jPanel1.setBackground(new java.awt.Color(255, 255, 255));
      jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

      textoParaQRCode.setColumns(20);
      
      textoParaQRCode.setRows(5);
      
      jScrollPane1.setViewportView(textoParaQRCode);
      
      btnGerar.setText(Gerar QR Code);
      
      btnGerar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      btnGerarActionPerformed(evt);
      
      }
      
      });
      
      btnLimpar.setText(Limpar Texto);
      
      btnLimpar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      btnLimparActionPerformed(evt);
      
      }
      
      });
      
      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      
      jPanel1.setLayout(jPanel1Layout);
      
      jPanel1Layout.setHorizontalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGap(179, 179, 179)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGap(244, 244, 244)
      
      .addComponent(btnGerar)
      
      .addGap(85, 85, 85)
      
      .addComponent(btnLimpar)))
      
      .addContainerGap(271, Short.MAX_VALUE))
      
      );
      
      jPanel1Layout.setVerticalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGap(39, 39, 39)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(41, 41, 41)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(btnGerar)
      
      .addComponent(btnLimpar))
      
      .addContainerGap(167, Short.MAX_VALUE))
      
      );
      

      getContentPane().add(jPanel1);
      jPanel1.setBounds(120, 40, 840, 370);

      jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/azul abstrato.jpg"))); // NOI18N
      
      getContentPane().add(jLabel1);
      
      jLabel1.setBounds(0, 0, 1920, 1357);
      
      setSize(new java.awt.Dimension(1100, 572));
      
      setLocationRelativeTo(null);
      
      }//
      
    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {
    
    textoParaQRCode.setText(null);
    
    }
    
    private void btnGerarActionPerformed(java.awt.event.ActionEvent evt) {
    
    //geraçao do QRCode
    
    int size = 125; //tamanho
    
    String nomeArquivo = Mattheus.png;//nome do arquivo de saida
    
    try (
    
    FileOutputStream f = new FileOutputStream(nomeArquivo);//fileout arquivo de saida
    
    ByteArrayOutputStream out = QRCode.from(textoParaQRCode.getText())
    
    .to(ImageType.PNG)
    
    .withSize(size,size)
    
    .stream();
    
    ){  
         f.write(out.toByteArray());//gravando o arquivo
            f.close();
            JOptionPane.showMessageDialog(rootPane, "ok", "Arquivo ",+nomeArquivo+" gerado com sucesso!",JOptionPane.INFORMATION_MESSAGE);
            
     } catch (IOException ex) {
         Logger.getLogger(QRCode.class.getName()).log(Level.SEVERE, null, ex);
     }
    

    }

    /**

    • @param args the command line arguments
      /
      public static void main(String args[]) {
      /
      Set the Nimbus look and feel /
      //
      /
      If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

      • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if (“Nimbus”.equals(info.getName())) {
        javax.swing.UIManager.setLookAndFeel(info.getClassName());
        break;
        }
        }
        } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(QRCode.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(QRCode.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(QRCode.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(QRCode.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //
      /* Create and display the form */
      
      java.awt.EventQueue.invokeLater(new Runnable() {
      
      public void run() {
      
      new QRCode().setVisible(true);
      
      }
      

      });
      }

    // Variables declaration - do not modify
    
    private javax.swing.JButton btnGerar;
    
    private javax.swing.JButton btnLimpar;
    
    private javax.swing.JLabel jLabel1;
    
    private javax.swing.JPanel jPanel1;
    
    private javax.swing.JScrollPane jScrollPane1;
    
    private javax.swing.JTextArea textoParaQRCode;
    
    // End of variables declaration
    
    }
    
Criado 18 de abril de 2018
Respostas 0
Participantes 1