The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


java ui components using buttons

Posted by jerry on December 09, 2000 at 6:00 AM


i am trying to add a button to a choice menu so that when i click on it will open the window so a user will be able to choose a selection.

i can create the button and the chocie menu , but when it comes to the action() event i am not sure what to due. the program fails to complie the way it is. i have tried several public class ChoiceMenu types but still no luck.

import java.awt.*;

public class Menus extends java.applet.Applet {

public void init() {

add(new Button("Motorcycles"));

Choice c = new Choice();

c.addItem("1967 Honda NightRider");
c.addItem("1994 Suzuki Ninja");
c.addItem("1972 Yamaha Striker");



public boolean action(Event evt, Object arg) {
if( instanceof Button)

return true;


void Bikes(String bname) {

if (bname.equals("Motorcycles")) handleChoice(new Choice());



after i name the arg. for the button , and create the new method . i cant find a way to call the arg. i have tried replacing new choice with just arg. that didnt work , then i added (String)arg , again that didnt work.

so i would greatly need any help you can give.

thank you jerry


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us