Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with interface implementation

17 views
Skip to first unread message

Amr

unread,
Feb 14, 2010, 4:24:55 AM2/14/10
to
hi all,
im following an excercise from the book "Sams teach yourself java in
21 days"
i typed the exercise exactly as in the book but i get an error. below
are the error and the full code of the program.
thank you very much for your help.

error:
Caused by: java.lang.RuntimeException: Uncompilable source code -
DayEleven.SurveryWizard is not abstract and does not override abstract
method actionPerformed(java.awt.event.ActionEvent) in
java.awt.event.ActionListener

im doing this excercise in Netbeans and it gives an option to
'implement all abstract methods' to get rid of this error.
doing that allows the compilation, but can't when go forward with the
second interface.

package DayEleven;

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

/**
*
* @author amr
*/
public class SurveryWizard extends JPanel implements ActionListener{
int currentCard=0;
CardLayout cards=new CardLayout();
SurveyPanel[] ask=new SurveyPanel[3];

public SurveryWizard(){
super();
setSize(240, 140);
//set up survery

String question1="What is your gender";
String[] response1={"female","male","not telling"};
ask[0]=new SurveyPanel(question1,response1,2);
String question2="What is your age";
String[] response2={"Under 25","25-34","35-40","over 54"};
ask[1]=new SurveyPanel(question1,response2,1);
String question3="How often do you excercise each week";
String[] responses3={"Never", "1-3 times","More than 3"};
ask[2]=new SurveyPanel(question3,responses3,1);
ask[2].setFinalQuestion(true);
for(int i=0; i<ask.length;i++){
ask[i].nextButton.addActionListener(this);
ask[i].finalButton.addActionListener(this);
add(ask[i],"Card",i);
}
}

public void actionPerformed(ActiveEvent evt){
currentCard++;
if(currentCard>=ask.length){
System.exit(0);
}
cards.show(this,"Card "+currentCard);
}


}
class SurveyPanel extends JPanel{
JLabel question;
JRadioButton[] response;
JButton nextButton=new JButton("Next");
JButton finalButton=new JButton("Finish");

public SurveyPanel(String ques, String[] resp, int def) {
super();
setSize(160, 110);
question =new JLabel(ques);
response=new JRadioButton[resp.length];
JPanel sub1=new JPanel();
ButtonGroup group=new ButtonGroup();
JLabel quesLabel=new JLabel(ques);
sub1.add(quesLabel);
JPanel sub2=new JPanel();
for(int i=0; i<resp.length;i++){
if(def==i){
response[i]=new JRadioButton(resp[i],true);
}else{
response[i]=new JRadioButton(resp[i],false);
}

group.add(response[i]);
sub2.add(response[i]);
}

JPanel sub3=new JPanel();
nextButton.setEnabled(true);
sub3.add(nextButton);
finalButton.setEnabled(false);
sub3.add(finalButton);
GridLayout grid=new GridLayout(3, 1);
setLayout(grid);
add(sub1);
add(sub2);
add(sub3);
}

void setFinalQuestion(boolean finalQuestion){
if(finalQuestion){
nextButton.setEnabled(false);
finalButton.setEnabled(true);
}
}
}

package DayEleven;

import javax.swing.JFrame;

/**
*
* @author amr
*/
public class SurveyFrame extends JFrame{
public SurveyFrame(){
super("Survery");
setSize(290, 140);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SurveryWizard wiz=new SurveryWizard();
add(wiz);
setVisible(true);

}

static public void main(String arg[]){
SurveyFrame surv=new SurveyFrame();
}

}

rossum

unread,
Feb 14, 2010, 7:40:23 AM2/14/10
to
On Sun, 14 Feb 2010 01:24:55 -0800 (PST), Amr
<fromwindo...@gmail.com> wrote:

>hi all,
>im following an excercise from the book "Sams teach yourself java in
>21 days"
>i typed the exercise exactly as in the book but i get an error. below
>are the error and the full code of the program.
>thank you very much for your help.
>
>error:
>Caused by: java.lang.RuntimeException: Uncompilable source code -
>DayEleven.SurveryWizard is not abstract and does not override abstract
>method actionPerformed(java.awt.event.ActionEvent) in
>java.awt.event.ActionListener

This is telling you that your class DayEleven.SurveryWizard does not
correctly override method actionPerformed(java.awt.event.ActionEvent)

That is where you need to look first for your error.

So, here is where you need to start looking.
> public void actionPerformed(ActiveEvent evt){
Look at the type of the parameter you are using here: ActiveEvent
Now go back and look at the typr of the parameter of the method you
are trying to override: ActionEvent

You are not overriding actionPerformed() but are overloading it
instead, which is probably not what you intended to do.

rossum

> currentCard++;
> if(currentCard>=ask.length){
> System.exit(0);
> }
> cards.show(this,"Card "+currentCard);
> }
>
>

[snip code]

Amr

unread,
Feb 14, 2010, 11:34:57 AM2/14/10
to
Thank you very much for the reply.
it solved part of the problem.
now i can't move to the next card. and i get this error:

Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: wrong parent for CardLayout
at java.awt.CardLayout.checkLayout(CardLayout.java:404)
at java.awt.CardLayout.show(CardLayout.java:526)
at DayEleven.SurveryWizard.actionPerformed(SurveryWizard.java:
50)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:
2012)
at javax.swing.AbstractButton
$Handler.actionPerformed(AbstractButton.java:2335)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:
404)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:
253)
at java.awt.Component.processMouseEvent(Component.java:6108)
at javax.swing.JComponent.processMouseEvent(JComponent.java:
3267)
at java.awt.Component.processEvent(Component.java:5873)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4469)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4295)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:
4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:
275)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:
200)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:
190)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:
138)


and it says,the error is in the last line of this code snippet:
public void actionPerformed(ActionEvent evt){


currentCard++;
if(currentCard>=ask.length){
System.exit(0);
}
cards.show(this,"Card "+currentCard);
}


thank you very much for your time.

Amr

unread,
Feb 14, 2010, 11:35:17 AM2/14/10
to

currentCard++;
if(currentCard>=ask.length){
System.exit(0);
}
cards.show(this,"Card "+currentCard);
}


thank you very much for your time.

markspace

unread,
Feb 14, 2010, 2:16:38 PM2/14/10
to
Amr wrote:
> Thank you very much for the reply.
> it solved part of the problem.
> now i can't move to the next card. and i get this error:
>
> Exception in thread "AWT-EventQueue-0"
> java.lang.IllegalArgumentException: wrong parent for CardLayout


This bit from your code that starts here seems wrong to me:

CardLayout cards=new CardLayout();
SurveyPanel[] ask=new SurveyPanel[3];

You don't use "cards" anywhere. Usually you have to set a container
with the required layout. You don't do this anywhere that I can see.
Maybe this is the "wrong parent," since the "this" doesn't have a
CardLayout?

Also, it seems wrong to keep each of the panels around separately, like
you do in the array named "ask". It seems CardLayout should take care
of holding those panels. Not sure about that however.

I've never had a good experience with Sam's books. Take a look at the
Java tutorial from Sun (nee Oracle) and their example, which is a bit
different in how it sets stuff up.

<http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html>

<http://java.sun.com/docs/books/tutorial/uiswing/examples/layout/CardLayoutDemoProject/src/layout/CardLayoutDemo.java>

rossum

unread,
Feb 14, 2010, 2:22:03 PM2/14/10
to
On Sun, 14 Feb 2010 08:34:57 -0800 (PST), Amr
<fromwindo...@gmail.com> wrote:

>Thank you very much for the reply.
>it solved part of the problem.
>now i can't move to the next card. and i get this error:
>
>Exception in thread "AWT-EventQueue-0"


This stuff has the latest first.

>java.lang.IllegalArgumentException: wrong parent for CardLayout

You have an IllegalArgumentException. Something about the CardLayout
you are passing.

> at java.awt.CardLayout.checkLayout(CardLayout.java:404)
It is probable that the CardLayout being referenced in this method is
faulty.

> at java.awt.CardLayout.show(CardLayout.java:526)
The probable faulty reference is within the code of the show() method.

> at DayEleven.SurveryWizard.actionPerformed(SurveryWizard.java:
>50)
This is where the problem is in your code. All previous source line
numbers were in Java code.

[snip rest of error]

>
>
>and it says,the error is in the last line of this code snippet:
> public void actionPerformed(ActionEvent evt){
> currentCard++;
> if(currentCard>=ask.length){
> System.exit(0);
> }
> cards.show(this,"Card "+currentCard);

One of these two parameters is probably faulty. I assume that the
second parameter "Card " + currentCard is a string so that is unlikely
to be the problem, though it is possible.

Your first parameter is 'this' Check what type 'this' is. Check what
type the show() method is expecting as its first parameter.

As I read your code fragment, 'this' refers to an instance of the
class that contains the actionPerformed() method. That may not be the
right type for show().

rossum

Lew

unread,
Feb 14, 2010, 2:48:45 PM2/14/10
to
markspace wrote:
> I've never had a good experience with Sam's books. Take a look at the
> Java tutorial from Sun (nee Oracle) and their example, which is a bit
> different in how it sets stuff up.
>
> <http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html>
>
> <http://java.sun.com/docs/books/tutorial/uiswing/examples/layout/CardLayoutDemoProject/src/layout/CardLayoutDemo.java>

That should be "Oracle (nee Sun)", since Java was born with family name "Sun"
and then married into the "Oracle" family.

--
Lew

Mike Schilling

unread,
Feb 14, 2010, 3:31:02 PM2/14/10
to

The correct use of "nee" can be found at
http://www.youtube.com/watch?v=0e2kaQqxmQ0


Joshua Cranmer

unread,
Feb 14, 2010, 3:38:08 PM2/14/10
to
On 02/14/2010 02:48 PM, Lew wrote:
> That should be "Oracle (nee Sun)", since Java was born with family name
> "Sun" and then married into the "Oracle" family.

To be most pedantic, it's né or née, depending on whether or not you
consider Java to be masculine or feminine. It's the past participle of
the French word 'naître', or 'to be born.'

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Lew

unread,
Feb 14, 2010, 3:48:52 PM2/14/10
to
Lew wrote:
>> That should be "Oracle (nee Sun)", since Java was born with family name
>> "Sun" and then married into the "Oracle" family.

Joshua Cranmer wrote:
> To be most pedantic, it's né or née, depending on whether or not you
> consider Java to be masculine or feminine. It's the past participle of
> the French word 'naître', or 'to be born.'

You are absolutely correct. I've received a lot of grief over being overly
pedantic in these fora, so I forbore to take it to that level. Nevertheless I
heartily endorse your observation.

Clearly Java must be feminine, as she's the one who changed her family name
when the marriage happened.

--
Lew
Marriage is a civil right.

Tom Anderson

unread,
Feb 14, 2010, 5:55:07 PM2/14/10
to
On Sun, 14 Feb 2010, Lew wrote:

> Lew wrote:
>>> That should be "Oracle (nee Sun)", since Java was born with family name
>>> "Sun" and then married into the "Oracle" family.
>>
> Joshua Cranmer wrote:

>> To be most pedantic, it's n? or n?e, depending on whether or not you

>> consider Java to be masculine or feminine. It's the past participle of the

>> French word 'na?tre', or 'to be born.'


>
> You are absolutely correct. I've received a lot of grief over being overly
> pedantic in these fora, so I forbore to take it to that level. Nevertheless
> I heartily endorse your observation.
>
> Clearly Java must be feminine, as she's the one who changed her family
> name when the marriage happened.

Now there's an assumption and a half! Java could well be feminine and
traditional, but could also be masculine and modern. A male friend of mine
is planning to adopt his fiancee's surname when they marry.

The real problem here, of course, is the French. Why does everything have
to be either male or female? Very silly. Hopefully we'll see this fixed in
the next major release.

tom

--
Remember Sammy Jankis.

Lew

unread,
Feb 14, 2010, 6:39:32 PM2/14/10
to
Lew wrote:
>> Clearly Java must be feminine, as she's the one who changed her family
>> name when the marriage happened.

Tom Anderson wrote:
> Now there's an assumption and a half! Java could well be feminine and
> traditional, but could also be masculine and modern. A male friend of
> mine is planning to adopt his fiancee's surname when they marry.

You could call it an assumption. I call it playing the odds. Your
(putatively) male friend is in a decided minority.

If you find out that someone changed their family name to their spouse's upon
marriage, without any further information, and had to place a bet on the
gender of that person, you are far, far more likely to win if you bet that the
person is female.

So until you provide evidence to the contrary, I'll go with Java née Sun.

Although the Oracle of Delphi was female. Hmm.

--
Lew

Alessio Stalla

unread,
Feb 16, 2010, 6:24:49 AM2/16/10
to

Italian has masculine/feminine gender distinctions for nouns and
adjectives, too.
Now Java is a programming language, and language ("linguaggio") is
male in Italian.
But Java is an island, too, and island ("isola") is female...
And Oracle ("oracolo") is male, even if there are female oracles, like
the Oracle of Delphi.

I wonder if in French it is so messy... ;)

> --
> Lew

Thomas Pornin

unread,
Feb 16, 2010, 7:37:01 AM2/16/10
to
According to Alessio Stalla <alessi...@gmail.com>:

> Italian has masculine/feminine gender distinctions for nouns and
> adjectives, too.
> Now Java is a programming language, and language ("linguaggio") is
> male in Italian.
> But Java is an island, too, and island ("isola") is female...
> And Oracle ("oracolo") is male, even if there are female oracles, like
> the Oracle of Delphi.
>
> I wonder if in French it is so messy... ;)

In French, genders are the same than in Italian for these nouns. It does
not feel messy at all. French does not have a neutral gender, so every
single noun is either masculine or feminine (with a few odd idiomatic
exceptions such as "gens" ["people"], which is feminine on the left and
masculine on the right, and "amour" ["love"], which switches gender when
made plural -- an everlasting source of jokes for bored linguists after
too alcoholic a meal). When all inanimate objects have a gender, the
endless american debates on how to avoid sexism in speach tend to look a
bit ridiculous.

In everyday talk between programmers, programming languages, including
Java, are masculine, and nobody finds it the slightest odd.

Also, French law makes it legal for the husband to use his wife's name,
if he wishes so.


--Thomas Pornin

Robert Klemme

unread,
Feb 19, 2010, 12:32:05 PM2/19/10
to

May I throw in another language? In German we have masculine, feminine
and neuter. Also, I believe not the oracle was male or female: the
voices of the oracle were female. Which gives a certain indication as
to the gender of Python. But what does it tell us about the gender of
PL/SQL? In German coffee is male so Java might be male as well...

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Mike Schilling

unread,
Feb 19, 2010, 12:36:50 PM2/19/10
to
Robert Klemme wrote:
> May I throw in another language? In German we have masculine,
> feminine and neuter. Also, I believe not the oracle was male or
> female: the voices of the oracle were female. Which gives a certain
> indication as to the gender of Python. But what does it tell us
> about the gender of PL/SQL? In German coffee is male so Java might
> be male as well...

Though if you created a subset of Java, say for teaching children to
program, it would be neuter, assuming it's called Javalein or Javachen.


Robert Klemme

unread,
Feb 19, 2010, 4:13:51 PM2/19/10
to

Isn't that "JavaScript"?

Mike Schilling

unread,
Feb 19, 2010, 5:02:11 PM2/19/10
to

"Robert Klemme" <short...@googlemail.com> wrote in message
news:7u8d8s...@mid.individual.net...

> On 19.02.2010 18:36, Mike Schilling wrote:
>> Robert Klemme wrote:
>>> May I throw in another language? In German we have masculine,
>>> feminine and neuter. Also, I believe not the oracle was male or
>>> female: the voices of the oracle were female. Which gives a certain
>>> indication as to the gender of Python. But what does it tell us
>>> about the gender of PL/SQL? In German coffee is male so Java might
>>> be male as well...
>>
>> Though if you created a subset of Java, say for teaching children to
>> program, it would be neuter, assuming it's called Javalein or Javachen.
>
> Isn't that "JavaScript"?

JavaScript and Java are wholly unrelated, except for their names.


Robert Klemme

unread,
Feb 21, 2010, 8:49:07 AM2/21/10
to

There, got you! :-))

0 new messages