Erro no meu JFrame, não tem um método principal [Netbeans 8.1, Java SE]

5 respostas Resolvido
java
M

Quando rodo o meu JFrame, retorna uma mensagem de erro: “A classe ‘Banco.Dados’ não tem um método principal!”

Eu tentei isso:

public static void main(String[] args) {
    Dados d = new Dados();
    d.setVisible(true);
}

Roda sem dá nenhum erro, porém, o JFrame simplesmente não aparece!

5 Respostas

C

Mostra teu codigo, da Classe Dados, onde ce constroi o JFrame

M

Você deve ter esquecido de por nome_do_frame.setVisible(true);

M

/*

  • 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 Banco;

import javax.swing.JFrame;

/**
*

  • @author Hudson33
    */
    public class Dados extends javax.swing.JPanel {

    /**

    • Creates new form Dados
      */
      public Dados() {
      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() {
      

      jScrollPane1 = new javax.swing.JScrollPane();
      jTable1 = new javax.swing.JTable();

      jTable1.setModel(new javax.swing.table.DefaultTableModel(
      
      new Object [][] {
      
      {null, null, null, null},
      
      {null, null, null, null},
      
      {null, null, null, null},
      
      {null, null, null, null}
      
      },
      
      new String [] {
      
      Title 1, Title 2, Title 3, Title 4
      
      }
      
      ));
      
      jScrollPane1.setViewportView(jTable1);
      
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
      
      this.setLayout(layout);
      
      layout.setHorizontalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      
      .addContainerGap(15, Short.MAX_VALUE)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addContainerGap())
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      
      .addContainerGap(196, Short.MAX_VALUE)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addContainerGap())
      
      );
      
      }//
      
    // Variables declaration - do not modify
    
    private javax.swing.JScrollPane jScrollPane1;
    
    private javax.swing.JTable jTable1;
    
    // End of variables declaration
    

}

C

setVisible(true) ?

M
Solucao aceita

Já consegui resolver meu problema: Aquilo era um JPanel, não um JFrame.

Criado 29 de agosto de 2016
Ultima resposta 30 de ago. de 2016
Respostas 5
Participantes 3