Here is a snippet of code (not complete, but to show the problem I
get)
I'm trying to add 2 radio buttons b1 and b2 to a group bg.
But the compiler always complains of an "<identifier> expected " .
I think I'm not doing anything wrong here, this is pretty
straightforward code.
However, my cheers to anyone who can point me to what's wrong and how
to get ir right!
code:
**
import javax.swing.*;
public class BG {
JRadioButton b1 = new JRadioButton( "first button" );
JRadioButton b2 = new JRadioButton( "second button" );
ButtonGroup bg = new ButtonGroup();
bg.add( b1 );
bg.add( b2 );
}
**
Thanks,
gklinux
Andrew Thompson - 15 Dec 2003 16:41 GMT
> Here is a snippet of code (not complete, but to show the problem I
> get)
....
> code:
> **
[quoted text clipped - 5 lines]
>
> ButtonGroup bg = new ButtonGroup();
BG()
{
> bg.add( b1 );
> bg.add( b2 );
}
> }
>
> **
Thomas Fritsch - 15 Dec 2003 17:08 GMT
learningjava schrieb:
>Here is a snippet of code (not complete, but to show the problem I
>get)
>
>I'm trying to add 2 radio buttons b1 and b2 to a group bg.
>But the compiler always complains of an "<identifier> expected " .
Posting the exact compiler error messages would have been very nice.
(Please remember next time!)
BG.java:8: <identifier> expected
bg.add( b1 );
^
BG.java:9: <identifier> expected
bg.add( b2 );
^
>I think I'm not doing anything wrong here, this is pretty
>straightforward code.
[quoted text clipped - 10 lines]
>
>ButtonGroup bg = new ButtonGroup();
public BG() // Constructor
{
>bg.add( b1 );
>bg.add( b2 );
// The 2 lines above don't make sense outside any method or constructor.
}
>}
>
[quoted text clipped - 3 lines]
>
>gklinux