473,498 Members | 1,704 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 addWindowListener()method, write code for itemStateChanged() 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 2434
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 addWindowListener()method, write code for itemStateChanged() 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
20755
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? ...
3
2396
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");...
3
2384
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...
7
2496
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...
3
4292
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",...
6
19222
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...
11
2197
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...
12
2141
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...
5
13299
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...
0
7165
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,...
0
7205
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...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
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...
1
4910
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...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
291
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...

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.