Problema ao executar o sistema no netbeans

1 resposta
java
T

Olá colegas. Estou tendo problema ao executar somente a Telaprincipal.java .
Utilizo netbeans e quando tendo executar somente a Telaprincipal.java, ele apresenta erro. Ele não abre. Abre somente quando executo a telalogin e acesso com um usuário cadastrado.
/*

  • 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 View;
import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;

import modeloConection.ConexaoBD;

/**
*

  • @author tiago
    */
    public class TelaPrincipal extends javax.swing.JFrame {

    ConexaoBD conecta= new ConexaoBD();
    
    public TelaPrincipal(String usuario) {
    
    initComponents();
    
    jLabelUsuario.setText(usuario);
    
    conecta.conexao();
    
    }
    
    private TelaPrincipal() {
    
    throw new UnsupportedOperationException(Not supported yet.); //To change body of generated methods, choose Tools | Templates.
    
    }
    

    /**

    • 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() {
      
      jInternalFrameBemVindo = new javax.swing.JInternalFrame();
      
      jPanelInternal = new javax.swing.JPanel();
      
      jLabel2 = new javax.swing.JLabel();
      
      jLabel3 = new javax.swing.JLabel();
      
      jLabel4 = new javax.swing.JLabel();
      
      jLabel5 = new javax.swing.JLabel();
      
      jLabel6 = new javax.swing.JLabel();
      
      jLabel7 = new javax.swing.JLabel();
      
      jButtonCadMed = new javax.swing.JButton();
      
      jButtonCadMed1 = new javax.swing.JButton();
      
      jButtonCadMed2 = new javax.swing.JButton();
      
      jButtonCadMed3 = new javax.swing.JButton();
      
      jButtonCadMed4 = new javax.swing.JButton();
      
      jButtonFechar = new javax.swing.JButton();
      
      jLabel8 = new javax.swing.JLabel();
      
      jLabel1 = new javax.swing.JLabel();
      
      jLabel9 = new javax.swing.JLabel();
      
      jLabel10 = new javax.swing.JLabel();
      
      jLabelUsuario = new javax.swing.JLabel();
      
      jLabelFundoPrincipal = new javax.swing.JLabel();
      
      jMenuBar1 = new javax.swing.JMenuBar();
      
      jMenuCadastros = new javax.swing.JMenu();
      
      jMenuItemCadMedico = new javax.swing.JMenuItem();
      
      jMenuItemCadPacientes = new javax.swing.JMenuItem();
      
      jMenuItemCadEnfermeiros = new javax.swing.JMenuItem();
      
      jMenuItemCadUsuarios = new javax.swing.JMenuItem();
      
      jMenuRelatorios = new javax.swing.JMenu();
      
      jMenuFerramentas = new javax.swing.JMenu();
      
      jMenuItemTelaBemVindo = new javax.swing.JMenuItem();
      
      jMenuSair = new javax.swing.JMenu();
      
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      
      setSize(new java.awt.Dimension(1280, 720));
      
      getContentPane().setLayout(null);
      
      jInternalFrameBemVindo.setTitle(Bem-Vindo);
      
      jInternalFrameBemVindo.setVisible(true);
      
      jInternalFrameBemVindo.getContentPane().setLayout(null);
      

      jPanelInternal.setBackground(new java.awt.Color(204, 204, 204));
      jPanelInternal.setLayout(null);

      jLabel2.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel2.setText(Médicos);
      
      jPanelInternal.add(jLabel2);
      
      jLabel2.setBounds(40, 210, 40, 20);
      
      jLabel3.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel3.setText(Enfermeiro(a));
      
      jPanelInternal.add(jLabel3);
      
      jLabel3.setBounds(40, 320, 70, 10);
      
      jLabel4.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel4.setText(Pacientes);
      
      jPanelInternal.add(jLabel4);
      
      jLabel4.setBounds(40, 430, 50, 10);
      
      jLabel5.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel5.setText(Relatórios);
      
      jPanelInternal.add(jLabel5);
      
      jLabel5.setBounds(40, 540, 70, 13);
      
      jLabel6.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel6.setText(Usuários);
      
      jPanelInternal.add(jLabel6);
      
      jLabel6.setBounds(50, 100, 50, 10);
      
      jLabel7.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jLabel7.setText(Fechar esta janela);
      
      jPanelInternal.add(jLabel7);
      
      jLabel7.setBounds(30, 620, 90, 13);
      
      jButtonCadMed.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/icon-Doctor-Male-64-64-icon.png"))); // NOI18N
      
      jButtonCadMed.setToolTipText(Cadastro de Médicos);
      
      jButtonCadMed.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jButtonCadMedActionPerformed(evt);
      
      }
      
      });
      
      jPanelInternal.add(jButtonCadMed);
      
      jButtonCadMed.setBounds(10, 120, 120, 110);
      
      jButtonCadMed1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Medical-enfermeira-Female-Dark-64-64-icon.png"))); // NOI18N
      
      jButtonCadMed1.setToolTipText(Cadastro de Enfermeiros);
      
      jPanelInternal.add(jButtonCadMed1);
      
      jButtonCadMed1.setBounds(10, 230, 120, 110);
      
      jButtonCadMed2.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jButtonCadMed2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/iconPatient-Male-icon.png"))); // NOI18N
      
      jButtonCadMed2.setToolTipText(Cadastro de Pacientes);
      
      jPanelInternal.add(jButtonCadMed2);
      
      jButtonCadMed2.setBounds(10, 340, 120, 110);
      
      jButtonCadMed3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/analytics-icon.png"))); // NOI18N
      
      jButtonCadMed3.setToolTipText(Relatórios);
      
      jPanelInternal.add(jButtonCadMed3);
      
      jButtonCadMed3.setBounds(10, 450, 120, 110);
      
      jButtonCadMed4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/customer-service-icon.png"))); // NOI18N
      
      jButtonCadMed4.setToolTipText(Cadastro de Usuarios);
      
      jButtonCadMed4.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jButtonCadMed4ActionPerformed(evt);
      
      }
      
      });
      
      jPanelInternal.add(jButtonCadMed4);
      
      jButtonCadMed4.setBounds(10, 10, 120, 110);
      
      jButtonFechar.setFont(new java.awt.Font(Tahoma, 0, 10)); // NOI18N
      
      jButtonFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/turn-off-icon.png"))); // NOI18N
      
      jButtonFechar.setToolTipText(Fecha apenas essa janela);
      
      jButtonFechar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jButtonFecharActionPerformed(evt);
      
      }
      
      });
      
      jPanelInternal.add(jButtonFechar);
      
      jButtonFechar.setBounds(10, 560, 120, 80);
      

      jInternalFrameBemVindo.getContentPane().add(jPanelInternal);
      jPanelInternal.setBounds(0, 0, 150, 640);

      getContentPane().add(jInternalFrameBemVindo);
      jInternalFrameBemVindo.setBounds(0, 0, 160, 680);

      jLabel8.setFont(new java.awt.Font(Tahoma, 0, 18)); // NOI18N
      
      jLabel8.setForeground(new java.awt.Color(255, 255, 255));
      
      jLabel8.setText("Sistema de Agenda e Consulta ");
      
      getContentPane().add(jLabel8);
      
      jLabel8.setBounds(290, 120, 260, 22);
      
      jLabel1.setFont(new java.awt.Font(Tahoma, 1, 14)); // NOI18N
      
      jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/—Pngtree—medical logo_128-128.png"))); // NOI18N
      
      getContentPane().add(jLabel1);
      
      jLabel1.setBounds(170, 40, 140, 130);
      
      jLabel9.setFont(new java.awt.Font(Bookman Old Style, 1, 24)); // NOI18N
      
      jLabel9.setForeground(new java.awt.Color(255, 255, 255));
      
      jLabel9.setText("TGR Doctor ");
      
      getContentPane().add(jLabel9);
      
      jLabel9.setBounds(290, 80, 160, 30);
      
      jLabel10.setText(Usuário:);
      
      getContentPane().add(jLabel10);
      
      jLabel10.setBounds(880, 10, 50, 14);
      
      jLabelUsuario.setText(jLabel11);
      
      getContentPane().add(jLabelUsuario);
      
      jLabelUsuario.setBounds(940, 10, 120, 14);
      
      jLabelFundoPrincipal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/foto-medica2.jpg"))); // NOI18N
      
      getContentPane().add(jLabelFundoPrincipal);
      
      jLabelFundoPrincipal.setBounds(0, 0, 1080, 710);
      

      jMenuCadastros.setText(“Cadastros”);

      jMenuItemCadMedico.setText(Médicos);
      
      jMenuItemCadMedico.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jMenuItemCadMedicoActionPerformed(evt);
      
      }
      
      });
      
      jMenuCadastros.add(jMenuItemCadMedico);
      

      jMenuItemCadPacientes.setText(“Pacientes”);
      jMenuCadastros.add(jMenuItemCadPacientes);

      jMenuItemCadEnfermeiros.setText(“Enfermeiros”);
      jMenuCadastros.add(jMenuItemCadEnfermeiros);

      jMenuItemCadUsuarios.setText(“Usuários”);
      jMenuCadastros.add(jMenuItemCadUsuarios);

      jMenuBar1.add(jMenuCadastros);

      jMenuRelatorios.setText(“Relatórios”);
      jMenuBar1.add(jMenuRelatorios);

      jMenuFerramentas.setText(“Ferramentas”);

      jMenuItemTelaBemVindo.setText(Tela Bem Vindos);
      
      jMenuItemTelaBemVindo.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jMenuItemTelaBemVindoActionPerformed(evt);
      
      }
      
      });
      
      jMenuFerramentas.add(jMenuItemTelaBemVindo);
      

      jMenuBar1.add(jMenuFerramentas);

      jMenuSair.setText(Sair);
      
      jMenuSair.addMouseListener(new java.awt.event.MouseAdapter() {
      
      public void mouseClicked(java.awt.event.MouseEvent evt) {
      
      jMenuSairMouseClicked(evt);
      
      }
      
      });
      
      jMenuBar1.add(jMenuSair);
      

      setJMenuBar(jMenuBar1);

      setSize(new java.awt.Dimension(1094, 798));
      
      setLocationRelativeTo(null);
      
      }//
      
    private void jMenuItemTelaBemVindoActionPerformed(java.awt.event.ActionEvent evt) {
    
    jInternalFrameBemVindo.setVisible(true);
    
    }
    

    private void jMenuItemCadMedicoActionPerformed(java.awt.event.ActionEvent evt) {

    try {
         conecta.executaSql("select *from usuarios where usu_nome='"+jLabelUsuario.getText()+"'");
         conecta.rs.first();
         if(conecta.rs.getString("usu_tipo").equals("administrador")){
           FormMedico tela= new FormMedico();
           tela.setVisible(true);  
         }else{
         JOptionPane.showMessageDialog(rootPane, "Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema.");
         }
     } catch (SQLException ex) {
         JOptionPane.showMessageDialog(rootPane, "Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema."+ex);
     }
    

    }

    private void jButtonFecharActionPerformed(java.awt.event.ActionEvent evt) {
    
    jInternalFrameBemVindo.dispose();
    
    }
    
    private void jButtonCadMedActionPerformed(java.awt.event.ActionEvent evt) {
    
    try {
    
    conecta.executaSql(select *from usuarios where usu_nome=’”+jLabelUsuario.getText()+"’");
    
    conecta.rs.first();
    
    if(conecta.rs.getString(usu_tipo).equals(administrador)){
    
    FormMedico tela= new FormMedico();
    
    tela.setVisible(true);
    
    }else{
    
    JOptionPane.showMessageDialog(rootPane, Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema.);
    
    }
    
    } catch (SQLException ex) {
    
    JOptionPane.showMessageDialog(rootPane, Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema.+ex);
    
    }
    
    }
    
    private void jMenuSairMouseClicked(java.awt.event.MouseEvent evt) {
    
    System.exit(0);
    
    }
    
    private void jButtonCadMed4ActionPerformed(java.awt.event.ActionEvent evt) {
    
    try {
    
    conecta.executaSql(select *from usuarios where usu_nome=’”+jLabelUsuario.getText()+"’");
    
    conecta.rs.first();
    
    if(conecta.rs.getString(usu_tipo).equals(administrador)){
    
    FormUsuario tela= new FormUsuario();
    
    tela.setVisible(true);
    
    }else{
    
    JOptionPane.showMessageDialog(rootPane, Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema.);
    
    }
    
    } catch (SQLException ex) {
    
    JOptionPane.showMessageDialog(rootPane, Você não tem permissão para essa funcionalidade.\n Contate o Administrador do sistema.+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(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.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 TelaPrincipal().setVisible(true);
      
      }
      
      });
      
      }
      
    // Variables declaration - do not modify
    
    private javax.swing.JButton jButtonCadMed;
    
    private javax.swing.JButton jButtonCadMed1;
    
    private javax.swing.JButton jButtonCadMed2;
    
    private javax.swing.JButton jButtonCadMed3;
    
    private javax.swing.JButton jButtonCadMed4;
    
    private javax.swing.JButton jButtonFechar;
    
    private javax.swing.JInternalFrame jInternalFrameBemVindo;
    
    private javax.swing.JLabel jLabel1;
    
    private javax.swing.JLabel jLabel10;
    
    private javax.swing.JLabel jLabel2;
    
    private javax.swing.JLabel jLabel3;
    
    private javax.swing.JLabel jLabel4;
    
    private javax.swing.JLabel jLabel5;
    
    private javax.swing.JLabel jLabel6;
    
    private javax.swing.JLabel jLabel7;
    
    private javax.swing.JLabel jLabel8;
    
    private javax.swing.JLabel jLabel9;
    
    private javax.swing.JLabel jLabelFundoPrincipal;
    
    private javax.swing.JLabel jLabelUsuario;
    
    private javax.swing.JMenuBar jMenuBar1;
    
    private javax.swing.JMenu jMenuCadastros;
    
    private javax.swing.JMenu jMenuFerramentas;
    
    private javax.swing.JMenuItem jMenuItemCadEnfermeiros;
    
    private javax.swing.JMenuItem jMenuItemCadMedico;
    
    private javax.swing.JMenuItem jMenuItemCadPacientes;
    
    private javax.swing.JMenuItem jMenuItemCadUsuarios;
    
    private javax.swing.JMenuItem jMenuItemTelaBemVindo;
    
    private javax.swing.JMenu jMenuRelatorios;
    
    private javax.swing.JMenu jMenuSair;
    
    private javax.swing.JPanel jPanelInternal;
    
    // End of variables declaration
    
    }
    


1 Resposta

S

Ao postar código no fórum formate o mesmo para facilitar a leitura:
formatacao-forum

Você tem esses construtores na sua classe:

public TelaPrincipal(String usuario) { // primeiro construtor
    initComponents();
    jLabelUsuario.setText(usuario);
    conecta.conexao();
}

private TelaPrincipal() { // segundo construtor
    throw new UnsupportedOperationException("Not supported yet.");
}

No método main você está chamando o segundo construtor. :man_shrugging:
A meu ver você deveria apagar esse construtor privado e sem parâmetros.

Criado 2 de fevereiro de 2021
Ultima resposta 2 de fev. de 2021
Respostas 1
Participantes 2