Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2008, 11:00 AM
Member
 
Join Date: Mar 2008
Posts: 20
themburu is on a distinguished road
Seriously need help on my listeners!!
Hi I have a applet code which I'm trying to add listeners but its really disturbing me.

What coulb be wrong with it, plus also how do I add listeers for the checkboxes which grouped and also the Choice list?

When I compile the code it gives me this errors
1.myRequest is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
2. addComponentListener(java.awt.event.ComponentListe ner) in java.awt.Component cannot be applied to (myRequest)

I'm using JCreator 4.50 pro and jdk1.6.0_02

Here's ma code
Attached Files
File Type: txt myRequest.txt (6.1 KB, 6 views)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-23-2008, 02:55 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
It would be easier if you show the code.
1. I guess you are not implementing actionPerformed(java.awt.event.ActionEvent) in your myRequest class that extends java.awt.event.ActionListener. An you have to do that if you pan to instantiate myRequest. By the way use capitals for your class names: MyRequest.

2. addComponentListener(java.awt.event.ComponentListe ner) in java.awt.Component cannot be applied to (myRequest) means myRequest is not a ComponentListener and I guess that is true since it extends ActionListener.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-24-2008, 01:41 PM
Member
 
Join Date: Mar 2008
Posts: 20
themburu is on a distinguished road
myRequest code
The code is attached below my post thread or should I paste it here

import java.awt.*; //import the whole awt package
import javax.swing.JApplet; //import class JApplet
import java.awt.Graphics; //import class Graphics
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;


public class myRequest extends java.applet.Applet implements ActionListener{

//Create chekboxes which determine the kind of interaction the user wants
CheckboxGroup theGroup = new CheckboxGroup();
Checkbox c1 = new Checkbox("Distances", theGroup, true);
Checkbox c2 = new Checkbox("Health Facilities", theGroup, false);
Checkbox c3 = new Checkbox("Hotels & Accomondation", theGroup, false);
Checkbox c4 = new Checkbox("Government Offices", theGroup, false);
Checkbox c5 = new Checkbox("Supermarkets", theGroup, false);
Checkbox c6 = new Checkbox("Banks", theGroup, false);


//Create Choices so as to have a selection
Choice menus = new Choice();
Choice menus2 = new Choice();

//Create labels to indicate what happpens at each place
Label whereFrom = new Label("Where do you want to know?");
Label whereTo = new Label("Select the nearest point to where you are!");
//Label jeddy = new Label("Go to room D310");

//A button to send the selected request
Button report = new Button("Get Direction");


//Just to format font if I use g.drawString instead of the Label text
Font mm = new Font("Arial", Font.BOLD, 15);

//Add action listener
public void ActionPerformed(ActionEvent evt){
if (evt.getActionCommand().equals("Distances")){
setC1();
}
if (evt.getActionCommand().equals("Health Facilities")){
setC2();
}
if (evt.getActionCommand().equals("Hotels & Accomondation")){
setC3();
}
if (evt.getActionCommand().equals("Government Offices")){
setC4();
}
if (evt.getActionCommand().equals("Supermarkets")){
setC5();
}
if (evt.getActionCommand().equals("Banks")){
setC6();
}


repaint();
}

public void setC1(){
whereFrom.setText("Where do you want to know?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get Direction"); }
public void setC2(){
whereFrom.setText("Which hospital are you interested in?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Take me there"); }
public void setC3(){
whereFrom.setText("What Star hotel?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Give me a list"); }
public void setC4(){
whereFrom.setText("What Office are you interested in?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Show the office"); }
public void setC5(){
whereFrom.setText("Select the supermarket you are looking for?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get direction and prices"); }
public void setC6(){
whereFrom.setText("Which bank do you want?");
whereTo.setText("Select the nearest point to where you are!");
report.setLabel("Get bank and ATM's"); }

/** Initialization method that will be called after the applet is loaded
* into the browser.
*/

public void init() {

c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
c5.addItemListener(this);
c6.addItemListener(this);


menus.add("Select One");
menus.add("City Hall");
menus.add("Hilton");
menus.add("Nation Center");
menus.add("National Archives");
menus.add("680 Hotel");
menus.add("Electricity House");
menus.add("Times tower");
menus.addItem("Harambee House");
menus.addItem("Anniversary towers");
menus.addItem("Viewpark towers");
menus.addItem("Serena hotel");
menus.addItem("Nakumatt Lifestyle");
menus.addItem("I & M House");
menus.addItem("Barclays Head Office");


menus2.add("Select One");
menus2.add("City Hall");
menus2.add("Hilton");
menus2.add("Nation Center");
menus2.add("National Archives");
menus2.add("680 Hotel");
menus2.add("Electricity House");
menus2.add("Times tower");
menus2.addItem("Harambee House");
menus2.addItem("Anniversary towers");
menus2.addItem("Viewpark towers");
menus2.addItem("Serena hotel");
menus2.addItem("Nakumatt Lifestyle");
menus2.addItem("I & M House");
menus2.addItem("Barclays Head Office");

add(whereFrom);
add(whereTo);
add(menus);
add(menus2);
add(report);
add(c1);
add(c6);
add(c3);
add(c4);
add(c5);
add(c2);
// TODO start asynchronous download of heavy resources
}

public void paint(Graphics g) {
//Set positions for the Checkboxes

c1.setLocation(13,25);
c2.setLocation(120,25);
c3.setLocation(120,65);
c4.setLocation(120,45);
c5.setLocation(13,65);
c6.setLocation(13,45);
g.drawRect(5,3,275,100);

/**This part represents where I've used g.drawstring */
g.setFont(mm);
g.setColor(Color.BLUE);
g.drawString("What Help would you like on ?" , 8,19);
//g.drawString("Where do you want to know?" ,10 ,25);
//g.drawRect(5,10,180,25);
// g.drawString("Select the nearest point to where you are!",3, 130);
//g.drawRect(1,115,240,25);


/**This part I've used Labels */
whereFrom.setLocation(10,115);
whereTo.setLocation(6, 180);

/*These are the Choices */
menus.setLocation(15,140);
menus2.setLocation(15,210);

report.setLocation(180,250);

//g.drawString("Rm D310",15, 300);
//jeddy.setLocation(78,300);
}
}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-24-2008, 10:54 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
You should put your code between UBB code markers.
The error are caused by:

1. public void ActionPerformed(ActionEvent evt){
Java is case sensitive. The name should be: actionPerformed
2. in the original code you were trying to add an action listener as a component listener.

What do you try to solve?
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-26-2008, 11:41 AM
Member
 
Join Date: Mar 2008
Posts: 20
themburu is on a distinguished road
good work n still more problems!
Now thanks for your help I was able to create action listener for the checkbox now here's the other challenge
1. Can I have a different String arrays so that as the checkboxes change the text in the labels I can also use this String array to change what appears in the choice list.
2. The problem reduces to: How can I make a choice use a String array just as the way you do it in a JComboBox?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple listeners per event Java Tip Java Tips 1 01-03-2008 11:06 AM
Action Event and Listeners lost1 New To Java 3 11-14-2007 05:26 AM


All times are GMT +3. The time now is 12:43 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org