Não consigo fazer link no meu programa

0 respostas
G

Estou tendo problemas para linkar a classe “SobrePrograma” para ser um dos itens da classe "Jwriter’…
eu coloco no botão de ação “Sobre” esse codigo

[color=darkred]new SobrePrograma(this, true).setVisible(true);[/color]

mas mesmo assim dá erro, o que devo fazer?

Embaixo estao os dois códigos de classes.

/*
 * Jwriter.java
 *
 * Created on 20 de Novembro de 2008, 08:35
 */

package Apresentacao;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;


/**
 *
 * @author  ALUNO
 */
public class Jwriter extends javax.swing.JDialog {
    
    private File arquivo;
    private boolean alterado;
    
    

    /** Creates new form Jwriter */
    public Jwriter(java.awt.Frame parent, boolean modal) {
       
        
        LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
        //Mostrandos os L&F:
        for(int i=0;i<looks.length;i++)
            System.out.println(looks[i].getName());
        
        //Alterar L&F:
        try {            
            UIManager.setLookAndFeel(looks[3].getClassName());
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception ex) {} 
        
        initComponents();
        
        alterado = false;
        alterarStatus(false);
    }

    /** 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtaInfo = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtaTexto = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jmiSalvar = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jmiSobre = new javax.swing.JMenuItem();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Informações sobre o arquivo:");

        jtaInfo.setColumns(20);
        jtaInfo.setRows(5);
        jScrollPane2.setViewportView(jtaInfo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 703, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jtaTexto.setColumns(20);
        jtaTexto.setRows(5);
        jtaTexto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtaTextoKeyTyped(evt);
            }
        });
        jScrollPane3.setViewportView(jtaTexto);

        getContentPane().add(jScrollPane3, java.awt.BorderLayout.CENTER);

        jMenu1.setText("Arquivo");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SPACE, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Abrir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jmiSalvar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, java.awt.event.InputEvent.CTRL_MASK));
        jmiSalvar.setText("Salvar");
        jmiSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSalvarActionPerformed(evt);
            }
        });
        jMenu1.add(jmiSalvar);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem3.setText("Exit");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Menu");

        jmiSobre.setText("Sobre");
        jmiSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSobreActionPerformed(evt);
            }
        });
        jMenu2.add(jmiSobre);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

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

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

    JFileChooser fc = new JFileChooser();
    
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        
        arquivo = fc.getSelectedFile();
        mostrarInfo();
        carregarArquivo();
        
        
        
    }
        
       
    
}                                          

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

   alterarStatus(true);
    
}                                 

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



}                                      

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


    
    if(alterado == false)
       return;
       
    
    //se o arquivo nao existir, ele abre uma janela de salvar como.
    if(arquivo == null){
        JFileChooser jf = new JFileChooser();
        jf.setFileSelectionMode(JFileChooser.FILES_ONLY);
        if(jf.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            arquivo = jf.getSelectedFile();
            if(!arquivo.exists()) {
                
                try{
                    arquivo.createNewFile();
                    
                }catch(IOException ex) {

                    JOptionPane.showMessageDialog(null, "Não foi possível criar o arquivo!");
                }
                
            }
        }
        
        
    }
        
    
    try {
        
    FileWriter fw = new FileWriter(arquivo);
    PrintWriter buffer = new PrintWriter(fw);
    buffer.print(jtaTexto.getText());
    buffer.close();
    fw.close();
    alterarStatus(false);
    } catch(IOException ex) {
        
        JOptionPane.showMessageDialog(this, "Erro ao enviar arquivo: " + ex.getMessage() + "Erro" + JOptionPane.ERROR_MESSAGE);
    }
    
    

}                                         

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

   
    if(alterado == true) {
        
        if(JOptionPane.showConfirmDialog(this, "Deseja salvar o texto? ") == JOptionPane.YES_NO_OPTION )
            jmiSalvarActionPerformed(evt);
        
    }
        
        System.exit(0);
   
    
}                                          

private void jmiSobreActionPerformed(java.awt.event.ActionEvent evt) {
  
    try {
        new SobrePrograma(this, true).setVisible(true);
    } catch (Exception e) {}
   
    
    
    
}

public void alterarStatus(boolean status) {
    
    alterado = status;
    jmiSalvar.setEnabled(status);
    
    if(arquivo != null)
        this.setTitle(arquivo.getName());
    else
        this.setTitle("[Novo arquivo]");
    
    if (status)
        this.setTitle(this.getTitle() + "*");
    //else
        //this.setTitle("");
    
}

public void mostrarInfo(){
    
    if(arquivo == null)
        return;
    //Zerar a textArea
        jtaInfo.setText("");
    //Adiciona os dados    
        jtaInfo.append("\nLendo arquivo " + arquivo.getName() + "...");
        jtaInfo.append("\nTamanho: " + (arquivo.length() / 1024) + " kb");
        jtaInfo.append("\nUltima modificação foi em " + new Date(arquivo.lastModified()));
        jtaInfo.append("\nLocalização: " + arquivo.getAbsolutePath());
        
        
        
    
}

public void carregarArquivo(){
    
    if(arquivo == null)
        return;
    jtaTexto.setText("");
    
    alterarStatus(false);
    
    
    
    try {
        
    FileReader fr = new FileReader(arquivo);
    BufferedReader buffer = new BufferedReader(fr);
    String linha;
    while((linha = buffer.readLine()) != null) {
        
        jtaTexto.append(linha + "\n");
        
    }
    
     }catch (FileNotFoundException ex) {
         JOptionPane.showMessageDialog(this, "Erro ao abrir o arquivo!", "Error" , JOptionPane.ERROR_MESSAGE); 
     }catch (IOException ex) {
         JOptionPane.showMessageDialog(this, "Erro ao ler o arquivo!", "Error" , JOptionPane.ERROR_MESSAGE); 
       }  
    
}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Jwriter dialog = new Jwriter(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JMenuItem jmiSalvar;
    private javax.swing.JMenuItem jmiSobre;
    private javax.swing.JTextArea jtaInfo;
    private javax.swing.JTextArea jtaTexto;
    // End of variables declaration

}

Essa é a classe no qual será linkada.

/*
 * SobrePrograma.java
 *
 * Created on 20 de Novembro de 2008, 15:45
 */

package Apresentacao;

/**
 *
 * @author  Guilherme
 */
public class SobrePrograma extends javax.swing.JDialog {

    /** Creates new form SobrePrograma */
    public SobrePrograma(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    SobrePrograma(Jwriter aThis, boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

  

    /** 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        lineBorder1 = (javax.swing.border.LineBorder)javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0));
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setFont(new java.awt.Font("Microsoft Sans Serif", 0, 12)); // NOI18N
        setIconImage(null);
        setLocationByPlatform(true);

        jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 18)); // NOI18N
        jLabel1.setText("GP - Editor de Textos");
        jLabel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel2.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel2.setText("Versão 1.0 Alpha ");

        jLabel4.setText("É o meu primeiro programa usando Swing!");

        jLabel5.setText("Espero ir melhorando ele até ser o melhor editor de Textos do mundo!");

        jLabel6.setText("Hehehehe     \\o/");

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

        jLabel7.setText("Produzido por Guilherme Paltian");

        jLabel8.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel8.setText("[email removido]");

        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(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(113, 113, 113)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel8)
                                .addComponent(jLabel7))))
                    .addComponent(jLabel5)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(57, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(266, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(75, 75, 75))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addGap(32, 32, 32)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(20, Short.MAX_VALUE))
        );

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 this.dispose();
}

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    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.border.LineBorder lineBorder1;
    // End of variables declaration

}

Problema já foi resolvido! :stuck_out_tongue:

Criado 20 de novembro de 2008
Respostas 0
Participantes 1