Article View: aus.computers.java
Article #974Re: Please Help
From: moz
Date: Tue, 29 Feb 2000 00:00
Date: Tue, 29 Feb 2000 00:00
102 lines
3729 bytes
3729 bytes
OK compiled and can be found at http://www.esearch.com.au/temp/Radios.html
Code at http://www.esearch.com.au/temp/Radios.java
Moz
fiveten@ptd.net wrote:
> Thats the point though. tisnt working. Its broken.
>
> I get an error even trying to 'implements ItemListener'
>
> Can someone please compile the code and fix it... or at least tell me how to use ItemListeners w/ Checkboxes,
>
> thanks
> 510
>
> > fiveten@ptd.net wrote:
> >
> > > Hi, first message here, i have a huge problem, i'v had this code for
> > > days and cant get the ItemListener part to work, could you all help me
> > > out a bit ??? i'm just learning the lang and cant find any help in the
> > > API, thanks a ton. (ps> i'm coding in AWT jdk1.1)
> > >
> > > thanks again,
> > > 510
> > >
> > > ps> if its not too much could you respond to email: fiveten@ptd.net
> > > since i can only get email at home, thanks
> > > ///////////////////////////////////////////////////////////////////////////////////////////////////////
> > >
> >
> > Ok you seem to have the event handling code a bit mixed up. This is how it should look:
> >
> > >
> > > import java.awt.event.*;
> > > import java.awt.*;
> > > import java.*;
> > > import java.applet.Applet;
> > >
> > > public class Radios extends Applet implements ItemListener
> > > {
> > >
> > > static String str1 = "String One";
> > > static String str2 = "String Two";
> > > static String na = "Previous Option N/A";
> > >
> > > TextField text = new TextField("Null");
> > > Checkbox radio1 = new Checkbox();
> > > Checkbox radio2 = new Checkbox();
> > > Checkbox box1 = new Checkbox("Toggle");
> > > Panel p1;
> > > // ItemListener I = new ItemListener();
> > >
> > > public Radios()
> > > {
> > > // Create New
> > >
> > > CheckboxGroup group = new CheckboxGroup();
> > > radio1 = new Checkbox(str1, group, false);
> > > radio2 = new Checkbox(str2, group, false);
> > >
> > > radio1.addItemListener(this);
> > > radio2.addItemListener(this);
> > > box1.addItemListener(this);
> > >
> > > //sets up the window and Layout
> > > p1 = new Panel();
> > > p1.setLayout(new GridLayout(8,0));
> > > p1.add(radio1);
> > > p1.add(radio2);
> > > p1.add(box1);
> > > p1.add(text);
> > > add(p1);
> > >
> > > }
> > >
> >
> > > public void itemStateChanged(ItemEvent e){
> >
> > > if (e.getLabel() == str1) //Some Swing pieces in here, gotta
> > > text.setText(str1); //convert them to awt simillar
> > > if (e.getLabel() == str2)
> > > text.setText(str2);
> >
> > > if (box1.getState()==true) //true == on {
> >
> > > radio2.setState(false); //disable radio2
> > > if (text.getText().equals(str2)) //If text ='d st2, now its N/A
> > > text.setText(na);
> > > }
> > > else
> > > {
> > > radio2.setState(true); //box off, enable radio2,
> > > if (text.getText().equals(na)) //if text was N/A, make it
> > > text.setText(str2); //Previous Option (Str2)
> > > }
> > >
> > > }
> > >
> > > }
Technical Details
Message-ID:
<38BB9E0D.C124A0A5@iinet.net.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38B94ECA.25870E24@ptd.net> <38B9A185.DF261B67@iinet.net.au> <38BAF78D.FF9A9AD3@ptd.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,6d08219f0b3c18be X-Google-Attributes: gid10d6db,public From: moz <moz@iinet.net.au> Subject: Re: Please Help Date: 2000/02/29 Message-ID: <38BB9E0D.C124A0A5@iinet.net.au> X-Deja-AN: 591246026 Content-Transfer-Encoding: 7bit References: <38B94ECA.25870E24@ptd.net> <38B9A185.DF261B67@iinet.net.au> <38BAF78D.FF9A9AD3@ptd.net> Content-Type: text/plain; charset=us-ascii X-Trace: news.iinet.net.au 951819464 30548 mozzy@203.62.155.178 MIME-Version: 1.0 Newsgroups: aus.computers.java