• Post Reply Bookmark Topic Watch Topic
  • New Topic

One last big of help please  RSS feed

 
Antonio Aguilar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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]
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the method is actionPerformed(ActionEvent)
 
Antonio Aguilar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*bit, not big
 
Madhav Turangi
Greenhorn
Posts: 16
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your new code and tell us exactly what's happening.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!