🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #973

Re: Please Help

#973
From: fiveten
Date: Mon, 28 Feb 2000 00:00
94 lines
3508 bytes
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: <38BAF78D.FF9A9AD3@ptd.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38B94ECA.25870E24@ptd.net> <38B9A185.DF261B67@iinet.net.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,6d08219f0b3c18be
X-Google-Attributes: gid10d6db,public
From: fiveten@ptd.net
Subject: Re: Please Help
Date: 2000/02/28
Message-ID: <38BAF78D.FF9A9AD3@ptd.net>
X-Deja-AN: 591049332
Content-Transfer-Encoding: 7bit
References: <38B94ECA.25870E24@ptd.net> <38B9A185.DF261B67@iinet.net.au>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@ptd.net
X-Trace: nnrp1.ptd.net 951777638 204.186.71.85 (Mon, 28 Feb 2000 17:40:38 EST)
Organization: PenTeleData http://www.ptd.net
MIME-Version: 1.0
NNTP-Posting-Date: Mon, 28 Feb 2000 17:40:38 EST
Newsgroups: aus.computers.java