Results 1 to 7 of 7
- 09-28-2011, 01:06 PM #1
Member
- Join Date
- Sep 2011
- Location
- United Kingdom
- Posts
- 6
- Rep Power
- 0
Problem with JRadioButton and ButtonGroup - Identifier Expected error?
Hi guys, I'm new to Java and this is probably a really silly question, or at least is has a simple answer because I don't understand something, most probably...
Here is the contents of the file "OrderFrame":
The error lines are commented. What am I doing wrong?Java Code:import javax.swing.*; import java.awt.event.*; import java.awt.*; public class OrderFrame extends JFrame{ private JPanel BaseSelectPanel, SizeSelectPanel, ExtraSelectPanel, ToppingSelectPanel, NumberSelectPanel, PizzaPricePanel, DeliverySelectPanel, OrderSummaryPanel; private class BasePanel extends JPanel{ private JPanel BaseSelectPanel = new JPanel(); private JLabel BaseSelectLabel = new JLabel("Base type:"); private JRadioButton ItalianButton = new JRadioButton("Italian", true); private JRadioButton PanButton = new JRadioButton("Pan", false); private ButtonGroup RadioGroup = new ButtonGroup(); RadioGroup.add(ItalianButton); //Identifier expected? RadioGroup.add(PanButton); //Identifier expected? BasePanel.add(BaseSelectLabel); //Identifier expected? BasePanel.add(ItalianButton); //Identifier expected? BasePanel.add(PanButton); //Identifier expected? //I find that this.add does not work either, which one should I be using? } public OrderFrame(){ super("Pizza Hut UK Order Form"); this.setLayout(new FlowLayout()); this.setSize(800,600); BasePanel basepanel = new BasePanel(); add(basepanel); } }
Another thing I have found is that I have seen 'this.add' and '<name>.add' used... What does the 'this.' keyword do?
- 09-28-2011, 04:58 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Problem with JRadioButton and ButtonGroup - Identifier Expected error?
First of all use standard Java naming conventions. Variable names DO NOT start with an upper case character.
"RadioGroup" should be "radioGroup" etc...
You need to create a constructor for your BasePanel class. Then all the add(...) statements need to be moved to the constructor.
- 09-28-2011, 06:05 PM #3
Member
- Join Date
- Sep 2011
- Location
- United Kingdom
- Posts
- 6
- Rep Power
- 0
Re: Problem with JRadioButton and ButtonGroup - Identifier Expected error?
So lines 25 through 30 are not a constructor? What is meant by a constructor? I "googled" and found that 'a constructor is like a method, but not exactly like a method', and it creates a new instance of a class, but what does this mean and how do I use one?
- 09-28-2011, 06:18 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: Problem with JRadioButton and ButtonGroup - Identifier Expected error?
If you don't know what constructors are then i woudl suggest stepping away from Swing and learn the basics.
Start here, with the basics, specifically this section.
- 09-28-2011, 06:22 PM #5
Member
- Join Date
- Sep 2011
- Location
- United Kingdom
- Posts
- 6
- Rep Power
- 0
Re: Problem with JRadioButton and ButtonGroup - Identifier Expected error?
Yep I've read most of that today. I already know roughly what a class is and why oop is used from programming in C++, but all this nesting of things is tricky concept.
- 09-28-2011, 06:26 PM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Problem with JRadioButton and ButtonGroup - Identifier Expected error?
public OrderFrame() is a constructor for your OrderFrame class.
Now you need a public BasePanel() for the BasePanel class.
- 09-28-2011, 07:29 PM #7
Member
- Join Date
- Sep 2011
- Location
- United Kingdom
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
identifier expected error
By Java Learner in forum New To JavaReplies: 1Last Post: 04-27-2010, 08:13 PM -
Error:identifier expected(Help!)
By chhoton in forum New To JavaReplies: 8Last Post: 09-22-2009, 04:42 PM -
Setting selected JRadioButton in ButtonGroup
By emceenugget in forum AWT / SwingReplies: 3Last Post: 01-29-2009, 06:05 PM -
Identifier expected error
By vasu18 in forum New To JavaReplies: 1Last Post: 01-01-2008, 05:49 PM -
Error: <identifier> expected
By barney in forum AWT / SwingReplies: 2Last Post: 07-31-2007, 07:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks