• 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

One last big of help please

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so I've posted this before and a few of the comments helped (though there was someone who posted a link to an advertisement too). I've got this program down to one compiler error, shown here. Any suggestions to help me get past this last error would, as usual, be greatly appreciated.

Capture.PNG
[Thumbnail for Capture.PNG]
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What the error is saying is that you are saying that you're implementing ActionListener but you haven't given an implementation to one of its abstract methods (the name of the method is in the compiler message; I can't see it now). Basically, you need to override the method (same method name, same parameters) and make it work.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the method is actionPerformed(ActionEvent)
 
Antonio Aguilar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*bit, not big
 
Greenhorn
Posts: 16
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First change your calcWindow to CalcWindow (recommended naming convention), Though this does not cause compile error nor the reason for your current error.

By saying CalcWindow implements ActionListener you are forced (as you don't want to leave CalcWindow abstract) to implement
public void actionPerformed(ActionEvent e) method. It also means CalcWindow object/class is a ActionListener.


The ActionListener interface definition is

public interface ActionListener extends EventListener {
public void actionPerformed(ActionEvent e);
}



Line 33. calculate.addActionListener(this); registers button click handler, which is the same CalcWindow object (due to implements ActionListener).

JButton (type of calculate variable) has method
public void addActionListener(ActionListener l) which is what is invoked at line 33.

Your public double calculation(ActionEvent event) method should be public void actionPerformed(ActionEvent e). Because when the button is clicked the addActionListener(ActionListener l) method is called by AWT framework. Whatever is need to do when the button is clicked, should go into actionPerformed method. AWT cannot call any method we add into the class like calculation(ActionEvent event).
This method cannot return anything (return type is void), as dictated in ActionListener. Directly set the result into the result JTextArea from inside actionPerformed method.
 
Antonio Aguilar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is what I have so far and the program compiles but when I try to launch it, I get no GUI. Any suggestions?

 
Madhav Turangi
Greenhorn
Posts: 16
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
line 25. public void Window() is not constructor and is never invoked/executed. You may have to read/understand rules for constructors and how is it different from methods in more detail.
Its name should be exactly same as the class name and no return type mentioned. So your public void Window() (if intent to be constructor) must be public CalcWindow(). Remember constructor name must be CalcWindow() if class name is CalcWindow, case-sensitive.

There is an article http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html that might help understand how constructors differ from methods.
 
Antonio Aguilar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for that suggestion. I have the GUI running now that I implemented that but I don't get the output. I'm still digging into that bit now but if anyone has suggestions I'll be happy to hear them.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post your new code and tell us exactly what's happening.
 
reply
    Bookmark Topic Watch Topic
  • New Topic