Meu programa está dando erro em todos os statusField. O que fazer?

2 respostas
J
package textedit;

import java.io.*;
import java.util.*;
import javax.swing.*;

public class editorFrame extends javax.swing.JFrame {
    private int chooserValue;

    public editorFrame() {
        initComponents();
    }

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

        novoButton = new javax.swing.JButton();
        salvarButton = new javax.swing.JButton();
        abrirButton = new javax.swing.JButton();
        sairButton = new javax.swing.JButton();
        campoTexto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        areaTexto = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        novoButton.setText("Novo");
        novoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoButtonActionPerformed(evt);
            }
        });

        salvarButton.setText("Salvar");
        salvarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarButtonActionPerformed(evt);
            }
        });

        abrirButton.setText("Abrir");
        abrirButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abrirButtonActionPerformed(evt);
            }
        });

        sairButton.setText("Sair");
        sairButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairButtonActionPerformed(evt);
            }
        });

        areaTexto.setColumns(20);
        areaTexto.setLineWrap(true);
        areaTexto.setRows(5);
        areaTexto.setWrapStyleWord(true);
        jScrollPane1.setViewportView(areaTexto);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(novoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(salvarButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(abrirButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(sairButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(novoButton)
                    .addComponent(salvarButton)
                    .addComponent(abrirButton)
                    .addComponent(sairButton)
                    .addComponent(campoTexto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );

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

    private void sairButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        System.exit(0);
    }                                          

    private void novoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        areaTexto.setText("");
        statusField.setText("Novo arquivo");
    }                                          

    private void salvarButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        JFileChooser chooser = new JFileChooser();
        int chosserValue = chooser.showSaveDialog(this);
        
        if(chooserValue == JFileChooser.APPROVE_OPTION) {
            try {
                PrintWriter fout = new PrintWriter(chooser.getSelectedFile());
                fout.printf(areaTexto.getText());
                fout.close();
                statusField.setText("Salvado" + chooser.getSelectedFile().getAbsolutePath());
            } catch (FileNotFoundException ex) {
                Logger.getLogger(editorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
    }                                            

    private void abrirButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        JFileChooser chooser = new JFileChooser();
        int chooserValu = chooser.showOpenDialog(this);
        
        if(chooserValue == JFileChooser.APPROVE_OPTION){
            try{
                Scanner fin = new Scanner(chooser.getSelectedFile());
                String buffer = "";
                
                while(fin.hasNext()){
                    buffer += fin.nextLine() + "\n";
                }
                areaTexto.setText(buffer);
                fin.close();
                statusField.setText("Abriu" + chooser.getSelectedFile().getAbsolutePath());
            } catch(FileNotFoundException ex){
                JOptionPane.showMessageDialog(this, "Arquivo não encontrado!");
            }
        }
    }                                           

    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new editorFrame().setVisible(true);
            }
        });
    }
-
    // Variables declaration - do not modify                     
    private javax.swing.JButton abrirButton;
    private javax.swing.JTextArea areaTexto;
    private javax.swing.JTextField campoTexto;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton novoButton;
    private javax.swing.JButton sairButton;
    private javax.swing.JButton salvarButton;
    // End of variables declaration                   
}

2 Respostas

sowyer

quais erros?

ErickRAR

Em momento algum statusField está declarado.

Criado 22 de abril de 2014
Ultima resposta 25 de abr. de 2014
Respostas 2
Participantes 3