473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

beginner trouble with window listener, nested if statements

5 New Member
Ok-I am doing homework out of a book and the instructions are to display an interface with 5 option buttons in a frame. When clicked, each button changes the background color of the frame. It proceeds to tell me to construct CheckboxGroup, use FlowLayaout and add the Checkboxes to the frame along with ItemListener.
It says addWindowListen er()method, write code for itemStateChange d() which uses the getState() method and nested if statements.
--I am so stuck. I hate this book, it does not have any example close to this as to how to do it and I am so so stuck-PLEASE HELP!
This is how far I have gotten. Anything I have tried past this has not compiled.
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class ColorButtons extends Frame implements ItemListener
  5. {
  6.  
  7.  
  8. public static void main(String[] args)
  9. {
  10. }//end main arg
  11.  
  12.     //declare variables
  13.     boolean answer = false;
  14.  
  15.     //construct CheckboxGroup
  16.     CheckboxGroup sizeGroup = new CheckboxGroup();
  17.     Checkbox BlueBox = new Checkbox("Blue", true, sizeGroup);
  18.     Checkbox RedBox = new Checkbox("Red", false, sizeGroup);
  19.     Checkbox YellowBox = new Checkbox("Yellow", false, sizeGroup);
  20.     Checkbox PinkBox= new Checkbox("Pink", false, sizeGroup);
  21.     Checkbox GrayBox = new Checkbox("Gray", false, sizeGroup);
  22.  
  23.     //add components
  24. public void init()
  25. {
  26.         add(BlueBox);
  27.         BlueBox.addItemListener(this);
  28.         add(RedBox);
  29.         RedBox.addItemListener(this);
  30.         add(YellowBox);
  31.         YellowBox.addItemListener(this);
  32.         add(PinkBox);
  33.         PinkBox.addItemListener(this);
  34.         add(GrayBox);
  35.            GrayBox.addItemListener(this);
  36.  
  37.  
  38. }//end public void init
  39. //this method is triggered by the user clicking an option button
  40. public void itemStateChanged(ItemEvent choice)
  41. {
  42.  
  43. }//end itemStateChanged
  44.  
  45.      //if statements
  46. }//end public class
  47.  
Oct 22 '06 #1
1 2442
golom
2 New Member
Im a little confused by what you have writen, try the HelloWorldFrame tatourial! it will help get you started. also, If you are looking for a good book try

Java A Beginners Guide by Hebert schilt! Its informative and has many examples!

Remeber you need to write a runable method in main!



Ok-I am doing homework out of a book and the instructions are to display an interface with 5 option buttons in a frame. When clicked, each button changes the background color of the frame. It proceeds to tell me to construct CheckboxGroup, use FlowLayaout and add the Checkboxes to the frame along with ItemListener.
It says addWindowListen er()method, write code for itemStateChange d() which uses the getState() method and nested if statements.
--I am so stuck. I hate this book, it does not have any example close to this as to how to do it and I am so so stuck-PLEASE HELP!
This is how far I have gotten. Anything I have tried past this has not compiled.
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class ColorButtons extends Frame implements ItemListener
  5. {
  6.  
  7.  
  8. public static void main(String[] args)
  9. {
  10. }//end main arg  //this should not be here!
  11.  
  12.     //declare variables
  13.     boolean answer = false;
  14.  
  15.     //construct CheckboxGroup
  16.     CheckboxGroup sizeGroup = new CheckboxGroup();
  17.     Checkbox BlueBox = new Checkbox("Blue", true, sizeGroup);
  18.     Checkbox RedBox = new Checkbox("Red", false, sizeGroup);
  19.     Checkbox YellowBox = new Checkbox("Yellow", false, sizeGroup);
  20.     Checkbox PinkBox= new Checkbox("Pink", false, sizeGroup);
  21.     Checkbox GrayBox = new Checkbox("Gray", false, sizeGroup);
  22.  
  23.     //add components
  24. public void init()
  25. {
  26.         add(BlueBox);
  27.         BlueBox.addItemListener(this);
  28.         add(RedBox);
  29.         RedBox.addItemListener(this);
  30.         add(YellowBox);
  31.         YellowBox.addItemListener(this);
  32.         add(PinkBox);
  33.         PinkBox.addItemListener(this);
  34.         add(GrayBox);
  35.            GrayBox.addItemListener(this);
  36.  
  37.  
  38. }//end public void init
  39. //this method is triggered by the user clicking an option button
  40. public void itemStateChanged(ItemEvent choice)
  41. {
  42.  
  43. }//end itemStateChanged
  44.  
  45.      //if statements
  46. }//end public class
  47.  
Oct 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
20763
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? I seem to recall NS worked something like this: onmousedown=handleThat;
3
2400
by: Derek Basch | last post by:
Is it bad form to use the global window variable to reference an event handlers window? Like so: function SortableTable() { oFilterAdd = this.document.createElement("button"); oFilterAdd.setAttribute("type", "button"); oFilterAddText = this.document.createTextNode("Add");
3
2392
by: Paul Bowman | last post by:
Hi All Java has a facility where you can send output to a DOS window using System.out.println. This is useful while developing as you can see what it going in your code. Does .Net provide a similar facility? I notice that when a Windows app runs there is an output window that contains messages from the compiler etc. Is it possible to...
7
2503
by: Jaggu | last post by:
Hi , I need to close main window, once the child window succesfully opens else main window to remain. In my case when I close the main window immediately after the "window.open()" as mentioned below, both the main and child disappears(this is due to pop up blocker) disappears suddenly. I want to make the browser know if pop up blocks the...
3
4294
by: Jonathan | last post by:
Hi everyone, I've got a link that launches a little AJAX application in a window. Like this: function launchListener() { var newWindow = window.open("listener.php", "newWindow", "width=300,height=150"); }
6
19235
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I know, this shouldn't be an issue, but I just can't get it to work. The script only needs to work with Firefox/Mozilla, so XP code isn't an issue. I...
11
2206
by: gg9h0st | last post by:
i saw a code refactorying onload event listener window.onloadListeners=new Array(); window.addOnLoadListener=function(listener) { window.onloadListeners=listener; } why declare the onloadListeners, addOnLoadListener below window?
12
2149
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a test page and I've managed to bind the usercontrol to a repeater and display some data in the following fashion: <asp:Repeater ID="Repeater1"...
5
13321
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the...
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7743
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7986
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5391
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.