Welcome to Dream.In.Code
Become a Java Expert!

Join 150,189 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,051 people online right now. Registration is fast and FREE... Join Now!




Help with calling methods

 
Reply to this topicStart new topic

Help with calling methods

abgorn
24 Sep, 2008 - 09:14 AM
Post #1

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 912



Thanked: 5 times
Dream Kudos: 50
My Contributions
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:
java

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:

java

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)

This post has been edited by abgorn: 24 Sep, 2008 - 09:24 AM


Attached File(s)
Attached File  Text_Editor.zip ( 8.26k ) Number of downloads: 3
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Help With Calling Methods
24 Sep, 2008 - 09:34 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Are you getting any errors? OR is it just not doing anything?
User is offlineProfile CardPM
+Quote Post

abgorn
RE: Help With Calling Methods
24 Sep, 2008 - 10:02 AM
Post #3

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 912



Thanked: 5 times
Dream Kudos: 50
My Contributions
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


User is offlineProfile CardPM
+Quote Post

Locke37
RE: Help With Calling Methods
24 Sep, 2008 - 10:24 AM
Post #4

Contributor of the Year
Group Icon

Joined: 20 Mar, 2008
Posts: 1,274



Thanked: 57 times
Dream Kudos: 325
My Contributions
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! biggrin.gif

This post has been edited by Locke37: 24 Sep, 2008 - 10:27 AM
User is offlineProfile CardPM
+Quote Post

abgorn
RE: Help With Calling Methods
24 Sep, 2008 - 11:05 AM
Post #5

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 912



Thanked: 5 times
Dream Kudos: 50
My Contributions
That helps but I'm still not sure how to fix it.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Help With Calling Methods
24 Sep, 2008 - 11:44 AM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

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

java

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

User is offlineProfile CardPM
+Quote Post

johnmalloy
RE: Help With Calling Methods
24 Sep, 2008 - 11:48 AM
Post #7

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 8



Thanked: 2 times
My Contributions
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 Sep, 2008 - 11:51 AM
User is offlineProfile CardPM
+Quote Post

abgorn
RE: Help With Calling Methods
24 Sep, 2008 - 11:51 AM
Post #8

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 912



Thanked: 5 times
Dream Kudos: 50
My Contributions
Thanks for your help.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:11AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month