Como eu mantenho meus JButton salvo

Boa tarde colegas,

Eu estou precisando salvar as informações de uma ou duas classe quando o programa fosse fechado pra não perder esses botoes que é gerado por mim por um “gerador de botoes”, alem de as variaveis permanecerem com os dados que elas estavam antes de ser fechado o programa.
por exemplo,

                int X = 0 ;

com o decorrer do programa no momento em que eu vou fechar o programa essa variavel vale 10, e quando eu abrir o programa sera necessario que ela ainda continue valendo 10 e não 0 , por que se não o programa irar dar falha , e assim com muitas variaveis que está nessa classe.

entao eu queria salvar o “status” dessa(s) classe

Sem saber a real necessidade fica dificil. Mas uma ideia seria criar um TXT em um diretorio especifico e e escrever nele o numero que precisa persistir. E ler este mesmo txt toda vez que abrir o programa para carregar a info.

Você pode peristir em JSON, TXT, CSV, Criar um banco embarcado SQLITE, etc.
Existem várias alternativas.

Vc conseguer salvar um objeto num arquivo usando ObjectOutputStream: Java ObjectOutputStream (With Examples)

Então eu estou conseguindo gravar em uma arquivo .txt mas não consigo de jeito nenhum fazer o programa puxar essas informações de volta para o sistema

   public static void salvarBtn() {
   try { 
            
	ObjectOutputStream saida = new ObjectOutputStream(new FileOutputStream(arquivo));
            FileOutputStream file = new FileOutputStream("botoeslanche.txt");
	saida.writeObject(newbtnlanche);
            JOptionPane.showMessageDialog(null, "O ARQUIVO FOI GRAVADO");
            System.out.println(arquivo);
} catch (HeadlessException | IOException e) { 
	throw new RuntimeException(e); 
}

}

e as definições, ações, nomes, tamanho e etc estão sendo salvo certinho no arquivo

Como vc está fazendo para ler os objetos do arquivo?

public class jifcadlanche extends javax.swing.JInternalFrame {

   //Array dos botões lanche
 public static JButton newbtnlanche[] = new JButton[999999];

 static int qntdbtn;
 public static File arquivo = new File("botoeslanche.txt");


  //Salvando o botão em no arquivo
    public static void salvarBtn() {
  try { 
            
	ObjectOutputStream saida = new ObjectOutputStream(new 
           FileOutputStream(arquivo));
            FileOutputStream file = new FileOutputStream("botoeslanche.txt");
	saida.writeObject(newbtnlanche);
            JOptionPane.showMessageDialog(null, "O ARQUIVO FOI GRAVADO");
            System.out.println(arquivo);
} catch (HeadlessException | IOException e) { 
	throw new RuntimeException(e); 
}

}

Queria ver o código que vc está usando para ler. Esse que vc mandou é para escrever no arquivo. Para ler, deve ser usado o ObjectInputStream, veja: https://www.devmedia.com.br/introducao-a-serializacao-de-objetos/3050

ah sim, na verdade não conseguir usar nenhum metodo que conseguisse ler, então estou sem método.

Agora fiz uma e não consegue ler

           public static void carregarBtn(){
 try
{
  //Carrega o arquivo
 FileInputStream arquivoLeitura = new FileInputStream (arquivo);
        //Classe responsavel por recuperar os objetos do arquivo
  ObjectInputStream objLeitura = 
          new ObjectInputStream(arquivoLeitura);
  System.out.println(objLeitura.readObject());
  objLeitura.close();
  arquivoLeitura.close();
}
catch(IOException | ClassNotFoundException e) {
    JOptionPane.showMessageDialog(null,e + "O ARQUIVO NÃO FOI CARREGADO");
}

}

O erro é “java.ioStreamCorruptedException: invalid stream header: 00000000”

Achei uns exemplos na internet que vc pode comparar com seu código.

Salvar objeto em arquivo:

public void WriteObjectToFile(Object serObj) {
  try {
    FileOutputStream fileOut = new FileOutputStream(filepath);
    ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
    objectOut.writeObject(serObj);
    objectOut.close();
    System.out.println("The Object  was succesfully written to a file");
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}

FONTE: How to Write an Object to File in Java


Ler objeto de um arquivo:

public Object ReadObjectFromFile(String filepath) {
  try {
    FileInputStream fileIn = new FileInputStream(filepath);
    ObjectInputStream objectIn = new ObjectInputStream(fileIn);
    Object obj = objectIn.readObject();
    System.out.println("The Object has been read from the file");
    objectIn.close();
    
    return obj;
  } catch (Exception ex) {
    ex.printStackTrace();
    return null;
  }
}

FONTE: How to Read an Object from File in Java

Agora está lendo mas os botoes não aparecem de volta.
será que não ha outra forma de salvar o estado da UI do programa ?

Em vez de tentar salvar a instância do objeto, vc poderia armazenar apenas as características do botão, como label, tamanho, se está ativo ou não, etc.

Mas no caso das instâncias, talvez falte apenas forçar o repaint do frame. Acho que é soh chamar o método repaint().

Poderia me mostrar?
eu sou bem iniciante mesmo no java

Antes disso, vc poderia mandar o código do frame os botões devem ser adicionados logo após serem lidos do arquivo?

package Interface;

import static Interface.jifpedidos.jdpbebida;
import static Interface.jifpedidos.jdplanche;
import static Interface.jifresumo.jtblanches;
import ModuloConexao.ConnectionFactory;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import net.proteanit.sql.DbUtils;

public class jifcadlanche extends javax.swing.JInternalFrame {

//Array dos botões lanche
    public static JButton newbtnlanche[] = new JButton[999999];

    static int qntdbtn;
    public static File arquivo = new File("botoeslanche.txt");

//gravar no arquivo
    public void WriteObjectToFile(Object serObj) {
        try {
            FileOutputStream fileOut = new FileOutputStream(arquivo);
            try (ObjectOutputStream objectOut = new ObjectOutputStream(fileOut)) {
                objectOut.writeObject(newbtnlanche[1]);
            }
            JOptionPane.showMessageDialog(null, "O objeto foi gravado com sucesso em um arquivo");
            System.out.println("O objeto foi gravado com sucesso em um arquivo");
        } catch (HeadlessException | IOException ex) {
        }
    }

//ler arquivo
    public Object ReadObjectFromFile() {
        try {
            FileInputStream fileIn = new FileInputStream(arquivo);
            Object obj;
            try (ObjectInputStream objectIn = new ObjectInputStream(fileIn)) {
                obj = objectIn.readObject();
                JOptionPane.showMessageDialog(null, "O objeto foi lido do arquivo");
                System.out.println("O objeto foi lido do arquivo");

            }

            return obj;
        } catch (HeadlessException | IOException | ClassNotFoundException ex) {
            return null;
        }
    }

    int codcat;
    int tirarespaço;
    //  Codigo do Botão lanche
    int cod;
    int X = 0;

    //variaveis para criar mais espaço da categoria (LANCHES) vertical ao criar botoes
    int altfix = 810;
    int contvert = 0;
    int altura = 0;
    int jbcontvert = 2;
    int contlinha = 0;

    //variaveis para criar mais espaço da categoria (BEBIDAS) vertical ao criar botoes
    int altfixbebida = 810;
    int contvertbebida = 0;
    int alturabebida = 0;
    int jbcontvertbebida = 2;
    int contlinhabebida = 0;

    //variaveis para criar mais espaço da categoria (SOBREMESA) vertical ao criar botoes
    int altfixsobremesa = 810;
    int contvertsobremesa = 0;
    int alturasobremesa = 0;
    int jbcontvertsobremesa = 2;
    int contlinhasobremesa = 0;

    // Contador para gerar numero codigo da variavel dos botoes 
    int cont = 1;

    // Ação dos botoes 
    public static ActionListener btnCLickLanche = null;

    int somalanche;
    int somabebida;
    int somasobremesa;

    //Variaveis de conexão
    Connection conexao = null;
    PreparedStatement pst = null;
    ResultSet rs = null;

    private static jifcadlanche jifcadLanche;

    // Método que remove botão
    public void removerBotao(JButton button) {
        jdplanche.remove(button);
    }

    private void tabelalanche() {
        String sql = "select * from lanches where nome_lanche like ?";
        try {
            pst = conexao.prepareStatement(sql);

            pst.setString(1, jtpqs.getText() + "%");
            rs = pst.executeQuery();

            jtbaddlanche.setModel(DbUtils.resultSetToTableModel(rs));

        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, e);
        }

    }

    public void addlanche() {
        int Categoria = jcbcategoria.getSelectedIndex();

        String sql = "insert into lanches (nome_lanche,valor_lanche,tipo_categoria ) values (?,?,?)";

        try {

            pst = conexao.prepareStatement(sql);

            pst.setString(1, jtnome.getText());

            pst.setString(2, jftvalor.getText());

            if (Categoria == 0) {
                pst.setString(3, "Lanche");
            }
            if (Categoria == 1) {
                pst.setString(3, "Bebida");
            }

            pst.executeUpdate();

        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

    //Métodp que adiciona os botoes
    public void adicionarLanche() {

        // Recebendo valores Nome e valor do lanche
        String NomeLanche = jtnome.getText();
        String ValorLanche = jftvalor.getText();
        String o = aa.getText();
        int x = Integer.parseInt(o);

        int Categoria = jcbcategoria.getSelectedIndex();

        //Se nome lanche 
        if (NomeLanche.equals("")) {
        } else {
            if (ValorLanche.equals("")) {
            } else {

                // Codigo que será inserido na tabela de cadastro de lanche
                X = X + 1;// Contador que gera um "Código"

                String CodigoLanche = String.valueOf(X);// Convertendo um INTEIRO para STRINGS
                String cat = String.valueOf(codcat);
                //Ação que ao clicar no botão especifico do lanche ira adicionar na Comanda   
                btnCLickLanche = (ActionEvent evt) -> {
                    DefaultTableModel vall = (DefaultTableModel) jtblanches.getModel();
                    vall.addRow(new String[]{(newbtnlanche[x].getText()), ("1x"), (ValorLanche)});
                };

                //Listando na tabela
                //DefaultTableModel val = (DefaultTableModel) jtbaddlanche.getModel();
                //val.addRow(new String[]{cat,CodigoLanche, NomeLanche, ValorLanche});
                //CATEGORIA LANCHE
                if (Categoria == 0) {

                    // Adicionando botão
                    newbtnlanche[cont] = new JButton(NomeLanche);
                    //Largura e Altura do botão (Tamanho)
                    newbtnlanche[cont].setPreferredSize(new Dimension(140, 140));
                    //Fonte e tamanho do botão
                    newbtnlanche[cont].setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
                    // Gerenciador de Layout que organiza automaticamente aonde os botoes é inserido   
                    jdplanche.setLayout(new FlowLayout(FlowLayout.LEADING, 50, 50));

                    // Dando a ação ao botão
                    newbtnlanche[cont].addActionListener(btnCLickLanche);

                    // Adicionando o botão ao JDesktopPane = jdplanche
                    jifpedidos.jdplanche.add(newbtnlanche[cont]);

                    //contador que gera os numeros finais de cada variavel criada
                    cont = cont + 1;
                    contvert = contvert + 1;
                    jbcontvert = jbcontvert + 1;

                    // Gerador de espaço juntamente com os botões
                    if (jbcontvert == 4) {
                        jbcontvert = 1;
                    }
                    if (contvert >= 12) {
                        contvert = 12;
                    }

                    if (contvert == 12) {
                        if (jbcontvert == 3) {
                            contlinha = contlinha + 1;
                            altura = altura + 190;
                            somalanche = altfix + altura;
                            Dimension dlanche = new Dimension(0, somalanche);
                            jifpedidos.jdplanche.setPreferredSize(dlanche);
                            jifpedidos.jdplanche.setSize(dlanche);
                        }
                    }

                    codcat = 0;

                }
                //CATEGORIA BEBIDA
                if (Categoria == 1) {

                    // Adicionando botão
                    newbtnlanche[cont] = new JButton(NomeLanche);
                    //Largura e Altura do botão (Tamanho)
                    newbtnlanche[cont].setPreferredSize(new Dimension(140, 140));
                    //Fonte e tamanho do botão
                    newbtnlanche[cont].setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N

                    // Gerenciador de Layout que organiza automaticamente aonde os botoes é inserido   
                    jdpbebida.setLayout(new FlowLayout(FlowLayout.LEADING, 50, 50));

                    // Dando a ação ao botão
                    newbtnlanche[cont].addActionListener(btnCLickLanche);

                    // Adicionando o botão ao JDesktopPane = jdplanche
                    jifpedidos.jdpbebida.add(newbtnlanche[cont]);

                    //contador que gera os numeros finais de cada variavel criada
                    cont = cont + 1;
                    contvertbebida = contvertbebida + 1;
                    jbcontvertbebida = jbcontvertbebida + 1;

                    // Gerador de espaço juntamente com os botões
                    if (jbcontvertbebida == 4) {
                        jbcontvertbebida = 1;
                    }
                    if (contvertbebida >= 12) {
                        contvertbebida = 12;
                    }

                    if (contvertbebida == 12) {
                        if (jbcontvertbebida == 3) {
                            contlinhabebida = contlinhabebida + 1;
                            alturabebida = alturabebida + 190;
                            somabebida = altfixbebida + alturabebida;
                            Dimension dbebida = new Dimension(0, somabebida);
                            jifpedidos.jdpbebida.setPreferredSize(dbebida);
                            jifpedidos.jdpbebida.setSize(dbebida);
                        }
                    }

                    codcat = 1;

                }

                WriteObjectToFile("botoeslanche.txt");
            }

        }
    }

    // Instanciando o JinternalFrame de Cadastro de lanche 
    public static jifcadlanche getInstancia() {

        if (jifcadLanche == null) {
            jifcadLanche = new jifcadlanche();
        }
        return jifcadLanche;

    }

    public jifcadlanche() {
        initComponents();
        conexao = ConnectionFactory.conector();
    }

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

        jInternalFrame1 = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        jbadicionar = new javax.swing.JButton();
        jtnome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jcbcategoria = new javax.swing.JComboBox<>();
        itens = new javax.swing.JInternalFrame();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbaddlanche = new javax.swing.JTable();
        jbremover = new javax.swing.JButton();
        jftvalor = new javax.swing.JFormattedTextField();
        jtpqs = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        aa = new javax.swing.JTextField();

        jInternalFrame1.setVisible(true);

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        setClosable(true);
        setIconifiable(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jLabel1.setText("Nome");

        jbadicionar.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jbadicionar.setText("Adcionar");
        jbadicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbadicionarActionPerformed(evt);
            }
        });

        jtnome.setFont(new java.awt.Font("Arial", 0, 19)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jLabel2.setText("Valor");

        jLabel3.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jLabel3.setText("Categoria");

        jcbcategoria.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jcbcategoria.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Lanches", "Bebidas", "Sobremesas" }));

        itens.setResizable(true);
        itens.setTitle("Itens cadastrados");
        itens.setVisible(true);

        jtbaddlanche.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
        jtbaddlanche.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nome", "Valor"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbaddlanche.setRowHeight(30);
        jtbaddlanche.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbaddlancheMouseClicked(evt);
            }
        });
        jtbaddlanche.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtbaddlancheKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(jtbaddlanche);
        if (jtbaddlanche.getColumnModel().getColumnCount() > 0) {
            jtbaddlanche.getColumnModel().getColumn(0).setPreferredWidth(10);
            jtbaddlanche.getColumnModel().getColumn(1).setPreferredWidth(50);
        }

        javax.swing.GroupLayout itensLayout = new javax.swing.GroupLayout(itens.getContentPane());
        itens.getContentPane().setLayout(itensLayout);
        itensLayout.setHorizontalGroup(
            itensLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
        );
        itensLayout.setVerticalGroup(
            itensLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jbremover.setFont(new java.awt.Font("Arial", 0, 16)); // NOI18N
        jbremover.setText("Remover");
        jbremover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbremoverActionPerformed(evt);
            }
        });

        jftvalor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jftvalor.setFont(new java.awt.Font("Arial", 0, 19)); // NOI18N

        jButton1.setText("Alt");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        aa.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jftvalor, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                            .addComponent(jtnome)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jcbcategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtpqs))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbadicionar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbremover)
                                .addGap(28, 28, 28)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3))
                        .addGap(0, 7, Short.MAX_VALUE)))
                .addGap(10, 10, 10)
                .addComponent(itens, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(aa, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(itens)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtnome, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jftvalor, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbcategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtpqs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbadicionar)
                            .addComponent(jbremover)
                            .addComponent(jButton1))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(aa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>                        

    // Ação do botão adicionar 
    private void jbadicionarActionPerformed(java.awt.event.ActionEvent evt) {                                            
        adicionarLanche();
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///\/\/\/\/\/\/\/\/\/\/\/\\/\/\/\/\/\//\/\/\\/\//\//\//\//\//\//\//\//\//\//\//addlanche();
//\\//\\/\\//System.out.println(newbtnlanche[cont].getText());
        String strCont = String.valueOf(cont);// Convertendo um INTEIRO para STRINGS   
        aa.setText(strCont);
    }                                           

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {                                         
        jfprincipal.cadlanches = true;
        // Centralizando Tela    
        Dimension d = this.getDesktopPane().getSize();
        this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
        tabelalanche();
        String strCont = String.valueOf(cont);// Convertendo um INTEIRO para STRINGS   
        aa.setText(strCont);

    }                                        

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {                                          
        jfprincipal.cadlanches = false;

        ReadObjectFromFile();


    }                                         

// Ação do botão remover
    private void jbremoverActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if (codcat == 0) {

            //Chamando método que remove botão, "newbtnlanche" variavel dos botoes mais "cod" que diz quais dos botoes do array sera apagado
            removerBotao(newbtnlanche[cod]);

            //Removendo da tabela a informação relacionado ao botão removido
            ((DefaultTableModel) jtbaddlanche.getModel()).removeRow(jtbaddlanche.getSelectedRow());

            cod = 0;

            //contador que gera os numeros finais de cada variavel criada
            if (jbcontvert == 1) {
                jbcontvert = 4;
            }

            if (contvert >= 12) {
                contvert = 12;
            }

            if (contvert == 12) {
                jbcontvert = jbcontvert - 1;
                if (jbcontvert == 2) {

                    altura = altura - 190;
                    somalanche = somalanche - 190;
                    Dimension dlanche = new Dimension(0, somalanche);
                    jifpedidos.jdplanche.setPreferredSize(dlanche);
                    jifpedidos.jdplanche.setSize(dlanche);
                }
            }
        }
        System.out.println(jbcontvert);
    }                                         

    //ação do de quando mouse é clicado na tabela
    private void jtbaddlancheMouseClicked(java.awt.event.MouseEvent evt) {                                          
        //Linha selecionada da tabela
        int row = jtbaddlanche.getSelectedRow();

        // Obtendo valor da coluna 0 (primeira coluna) da linha selecionada (Row), "getValueAt(row, 0);"
        Object o = jtbaddlanche.getValueAt(row, 1);
        cod = Integer.parseInt((String) o);

        Object O = jtbaddlanche.getValueAt(row, 0);
        codcat = Integer.parseInt((String) O);


    }                                         


    private void jtbaddlancheKeyReleased(java.awt.event.KeyEvent evt) {                                         

    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String a;

        int o = Integer.parseInt(jtpqs.getText());
        newbtnlanche[o].setText(jtnome.getText());
    }                                        


    // Variables declaration - do not modify                     
    private javax.swing.JTextField aa;
    private javax.swing.JInternalFrame itens;
    private javax.swing.JButton jButton1;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbadicionar;
    private javax.swing.JButton jbremover;
    private javax.swing.JComboBox<String> jcbcategoria;
    private javax.swing.JFormattedTextField jftvalor;
    private javax.swing.JTable jtbaddlanche;
    public static javax.swing.JTextField jtnome;
    private javax.swing.JTextField jtpqs;
    // End of variables declaration                   
}