Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Swing / AWT / SWT
Help declaring radiobuttons....
Shawn Rieger
Greenhorn
Posts: 16
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Anyone have any idea why this doesn't work? I keep getting "<identifier> expected"
private JRadioButton jrbWall, jrbGable, jrbWindow, jrbDoor; jrbWall = new JRadioButton("Wall"); jrbGable = new JRadioButton("Gable"); jrbWindow = new JRadioButton("Window"); jrbDoor = new JRadioButton("Door");
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No problems with what you gave us...
import javax.swing.*; class Test { private JRadioButton jrbWall, jrbGable, jrbWindow, jrbDoor; Test() { jrbWall = new JRadioButton("Wall"); jrbGable = new JRadioButton("Gable"); jrbWindow = new JRadioButton("Window"); jrbDoor = new JRadioButton("Door"); } public static void main(String[] args) { new Test(); } }
If you look down the stack trace you'll often find a line number given which will point to the line in your source file where the trouble lies.
Shawn Rieger
Greenhorn
Posts: 16
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hmm... Well this is the actual code. Maybe i have it in the wrong spot cause im still getting errors.
import java.awt.*; import javax.swing.*; public class PaintEstimatorView extends JFrame { public static void main(String[] args) { PaintEstimatorView frame = new PaintEstimatorView(); frame.setSize(500, 380); //frame.setResizable(false); frame.setVisible(true); } /* Radio Buttons */ private JRadioButton jrbWall, jrbGable, jrbWindow, jrbDoor; jrbWall = new JRadioButton("Wall"); jrbGable = new JRadioButton("Gable"); jrbWindow = new JRadioButton("Window"); jrbDoor = new JRadioButton("Door"); private JLabel jlbSquareFt = new JLabel("Square Ft/Gallon ", JLabel.RIGHT); private JTextField jtfSquareFt = new JTextField("1"); public PaintEstimatorView() { Container container = getContentPane(); container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); ....
[ September 07, 2005: Message edited by: Shawn Rieger ]
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can do this
public class PEV extends JFrame { ... private JRadioButton jrbWall, jrbGable, jrbWindow, jrbDoor; public PEV() { jrbWall = new JRadioButton("Wall"); jrbGable = new JRadioButton("Gable"); jrbWindow = new JRadioButton("Window"); jrbDoor = new JRadioButton("Door"); Container container = getContentPane(); container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); }
or this
public class PEV extends JFrame { ... private JRadioButton jrbWall = new JRadioButton("Wall"); private JRadioButton jrbGable = new JRadioButton("Gable"); private JRadioButton jrbWindow = new JRadioButton("Window"); private JRadioButton jrbDoor = new JRadioButton("Door"); public PEV() { Container container = getContentPane(); container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); }
or even this
public class PEV extends JFrame { ... private JRadioButton jrbWall, jrbGable, jrbWindow, jrbDoor; { jrbWall = new JRadioButton("Wall"); jrbGable = new JRadioButton("Gable"); jrbWindow = new JRadioButton("Window"); jrbDoor = new JRadioButton("Door"); } public PEV() { Container container = getContentPane(); container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); }
but you may not put instantiations out in the open in a class; they must be inside a set of curley braces such as a method, constructor or initialization block.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Using same checkbox multiple times in an applet
JRadioButtons and newlines
10 shuffling question
ButtonGroup with JRadioButton
CHECKBOXGROUP.. newbie here :(
More...