• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

method ... not found in class ...

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having trouble with my GUI class not recognizing methods from a STACK class from the same package. Here's the skinny:
I have a GUI class named WordGUI.
I hava a STACK class named WordStack.
within WordGUI I instantiate an instance of a WordStack and call it myStack. Example below:
WordStack myStack = new WordStack();
When I call WordStack methods from WordGUI I get the error messages even though display and evaluate are methods from WordStack:
"WordGUI.java": Error #: 300 : method display(java.awt.Graphics, int) not found in class assign4.WordStack at line 34, column 13
"WordGUI.java": Error #: 300 : method evaluate(java.lang.String) not found in class assign4.WordStack at line 42, column 15
***********************************************
Complete code for both classes is below:

WordGUI class:
package assign4;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class WordGUI extends Applet implements ActionListener{
WordStack myStack = new WordStack();
private Button testButton;
private TextField wordField;
public void init(){
//add(myStack);
wordField = new TextField(20);
add(wordField);
wordField.addActionListener(this);
testButton = new Button("Test for palindromes");
add(testButton);
testButton.addActionListener(this);
}//init()
public void paint (Graphics g){
g.drawString("Enter a word in the textField above and click", 25, 100);
g.drawString("the button to check if the word is a palindrome", 25, 115);
myStack.display(g, 150);
}//paint()
public void actionPerformed(ActionEvent event){
if(event.getSource() == testButton){
String userInput = wordField.getText();
myStack.evaluate(userInput);
}
repaint();
}//actionPerformed()
}//class WordGUI
*********************************************
WordStack class:
package assign4;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class WordStack implements Cloneable{
private char[] data;
private int manyItems;
public WordStack(){
final int initialCapacity = 20;
manyItems = 0;
data = new char[initialCapacity];
}//generic constructor
public WordStack(int initialCapacity){
if(initialCapacity < 0){
throw new IllegalArgumentException
("initialCapacity too small: " + initialCapacity);
}
manyItems = 0;
data = new char[initialCapacity];
}//constructor
public int getCapacity(){
return data.length;
}//getCapacity()
public boolean isEmpty(){
return (manyItems == 0);
}//isEmpty()
public char pop(){
if(manyItems == 0){
//throw new EmptyStackException();
}
return data[--manyItems];
}//pop()
public void push(char item){
if(manyItems == data.length){
ensureCapacity(manyItems * 2 + 1);
}
data[manyItems] = item;
manyItems++;
}//push()
public void ensureCapacity(int minimumCapacity){
char biggerArray[];
if(data.length < minimumCapacity){
biggerArray = new char[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}//ensureCapacity()
public String evaluate(String userInput){
char charToProcess;
for(int charNum = 0; charNum < userInput.length(); charNum++){
push(userInput.charAt(charNum));
}
}//evaluate()
public void display(Graphics g, int yLoc){
for(int i = 0; i < data.length; i++){
g.drawString("" + data, 25, yLoc);
yLoc += 15;
}
}//display()
}//class WordStack
Any help would be appreciated greatly. Thank you
[ October 22, 2002: Message edited by: Thomas Paul ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt that you get those errors when you call any method, but probably when you try to compile.
I'm not sure what you're using (probably some IDE thingy), but if you compile the code with javac, you'd get:
WordStack.java:57: missing return statement
public String evaluate(String userInput){
Fix that and see if it'll compile....
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Russ,
Welcome to JavaRanch!
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand. Let's see what it would look like:
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Closing this thread in favor of this duplicate thread.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic