7 Replies - 910 Views - Last Post: 24 September 2008 - 12:51 PM Rate Topic: -----

#1 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Help with calling methods

Posted 24 September 2008 - 10:14 AM

I'm almost finished my project "nText" but I have one problem, I can't seem to call one of the classes. Here is the class that calls the other class:
package texteditor;

import java.awt.*;

public class TextEditor extends javax.swing.JFrame {
    public TextEditor() {
        initComponents();
    }
    
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        TextArea = new javax.swing.JTextPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        MenuItemNew = new javax.swing.JMenuItem();
        MenuItemOpen = new javax.swing.JMenuItem();
        MenuItemSave = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        manageFiles = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("nText");

        TextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        jScrollPane3.setViewportView(TextArea);

        FileMenu.setText("File");

        MenuItemNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        MenuItemNew.setText("New");
        MenuItemNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemNewActionPerformed(evt);
            }
        });
        MenuItemNew.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                MenuItemNewKeyReleased(evt);
            }
        });
        FileMenu.add(MenuItemNew);

        MenuItemOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        MenuItemOpen.setText("Open...");
        MenuItemOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemOpenActionPerformed(evt);
            }
        });
        MenuItemOpen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                MenuItemOpenKeyReleased(evt);
            }
        });
        FileMenu.add(MenuItemOpen);

        MenuItemSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        MenuItemSave.setText("Save");
        MenuItemSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuItemSaveActionPerformed(evt);
            }
        });
        MenuItemSave.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                MenuItemSaveKeyReleased(evt);
            }
        });
        FileMenu.add(MenuItemSave);
        FileMenu.add(jSeparator1);

        manageFiles.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        manageFiles.setText("Manage Files");
        manageFiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageFilesActionPerformed(evt);
            }
        });
        FileMenu.add(manageFiles);
        FileMenu.add(jSeparator2);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Exit");
        FileMenu.add(jMenuItem2);

        jMenuBar1.add(FileMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
        );

        pack();
    }

    private void MenuItemNewKeyReleased(java.awt.event.KeyEvent evt) {                                        
TextArea.setText("");
    }                                       

    private void MenuItemOpenKeyReleased(java.awt.event.KeyEvent evt) {                                         
OpenFile oFS =  new OpenFile();
    }                                        

    private void MenuItemNewActionPerformed(java.awt.event.ActionEvent evt) {                                            
TextArea.setText("");
    }                                           

    private void MenuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {                                             
        OpenFile oF =  new OpenFile();
    } 
                                           
//There is a error here when calling the class:
    private void MenuItemSaveActionPerformed(java.awt.event.ActionEvent evt) {                                             
WriteFileUI wFUI = new WriteFileUI();
    }                                            

//There is also the same problem here:
    private void MenuItemSaveKeyReleased(java.awt.event.KeyEvent evt) {                                         
WriteFileUI sWFUI = new WriteFileUI();
    }                                        

    private void manageFilesActionPerformed(java.awt.event.ActionEvent evt) {
FileManagmentUI fMUI = new FileManagmentUI();
}

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TextEditor().setVisible(true);
            }
        });
    }
    
    private javax.swing.JMenu FileMenu;
    private javax.swing.JMenuItem MenuItemNew;
    private javax.swing.JMenuItem MenuItemOpen;
    private javax.swing.JMenuItem MenuItemSave;
    public static javax.swing.JTextPane TextArea;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JMenuItem manageFiles;
}



And here is the class is tries to call:

package texteditor;

public class WriteFileUI extends javax.swing.JDialog {
    
    public WriteFileUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
                             
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        FileNameField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Save File...");

        jLabel1.setText("File Name:");

        jButton1.setText("Cancel");

        jButton2.setText("Save");

        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)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(10, 10, 10)
                        .addComponent(FileNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addGap(10, 10, 10))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(FileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                WriteFileUI dialog = new WriteFileUI(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);
            }
        });
    }
                      
    public static javax.swing.JTextField FileNameField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;                 
    
}



Can anyone help me fix this bug?

(the attatchment is the full source code for it)

Attached File(s)


This post has been edited by abgorn: 24 September 2008 - 10:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with calling methods

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help with calling methods

Posted 24 September 2008 - 10:34 AM

Are you getting any errors? OR is it just not doing anything?
Was This Post Helpful? 0
  • +
  • -

#3 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: Help with calling methods

Posted 24 September 2008 - 11:02 AM

I'm getting this error:
C:\Users\KENNY FAMILY\TextEditor\src\texteditor\TextEditor.java:125: cannot find symbol
symbol : constructor WriteFileUI()
location: class texteditor.WriteFileUI
WriteFileUI wFUI = new WriteFileUI();
C:\Users\KENNY FAMILY\TextEditor\src\texteditor\TextEditor.java:129: cannot find symbol
symbol : constructor WriteFileUI()
location: class texteditor.WriteFileUI
WriteFileUI sWFUI = new WriteFileUI();
2 errors

Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Help with calling methods

Posted 24 September 2008 - 11:24 AM

You only specified one constructor that accepts 2 parameters.

java.awt.Frame parent and boolean modal

When you try to call it with no parameters, it does not compile correctly.

Those are in lines 125 and 130, correct? You can't call a constructor that doesn't exist.

Hope this helps! :D

This post has been edited by Locke37: 24 September 2008 - 11:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: Help with calling methods

Posted 24 September 2008 - 12:05 PM

That helps but I'm still not sure how to fix it.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help with calling methods

Posted 24 September 2008 - 12:44 PM

You either pass it the 2 parameters it's looking for, or you create an empty constructor

public WriteFileUI(java.awt.Frame parent, boolean modal) { 
         initComponents();  
}  


Was This Post Helpful? 1
  • +
  • -

#7 johnmalloy  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 24-September 08

Re: Help with calling methods

Posted 24 September 2008 - 12:48 PM

Here is what he means:
You are calling the 2nd class as follows:
//There is a error here when calling the class:
private void MenuItemSaveActionPerformed(java.awt.event.ActionEvent evt) {
WriteFileUI wFUI = new WriteFileUI();
}

//There is also the same problem here:
private void MenuItemSaveKeyReleased(java.awt.event.KeyEvent evt) {
WriteFileUI sWFUI = new WriteFileUI();
}
But you are not passing any parameters to the class.
The problem is that the class default constructor requires "2" parameters to run.
So, either create another construtor that accepts no parameters or, what I suggest, add the needed parameters to the call. Example:
callClass(paraONE, paraTWO)
Hope this helps.

This post has been edited by johnmalloy: 24 September 2008 - 12:51 PM

Was This Post Helpful? 1
  • +
  • -

#8 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: Help with calling methods

Posted 24 September 2008 - 12:51 PM

Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1