Results 1 to 8 of 8
Thread: Hi Low Game errors
- 04-04-2011, 03:25 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
Hi Low Game errors
While compiling my code I am getting errors such as these:
.\BorderLayout.java:1: BorderLayout is already defined in this compilation unit
import java.awt.BorderLayout;
^
F:\Java\HiLowGame.java:54: cannot find symbol
symbol : constructor BorderLayout(int,int)
location: class BorderLayout
bcPanel.setLayout(new BorderLayout(3,1));
^
F:\Java\HiLowGame.java:60: setLayout(java.awt.LayoutManager) in java.awt.Container cannot be applied to (BorderLayout)
cPanel.setLayout(new BorderLayout());
^
F:\Java\HiLowGame.java:61: cannot find symbol
symbol : variable WEST
location: class BorderLayout
cPanel.add(tcPanel, BorderLayout.WEST);
^
F:\Java\HiLowGame.java:62: cannot find symbol
symbol : variable EAST
location: class BorderLayout
cPanel.add(bcPanel, BorderLayout.EAST);
^
F:\Java\HiLowGame.java:73: setLayout(java.awt.LayoutManager) in java.awt.Container cannot be applied to (BorderLayout)
this.setLayout(new BorderLayout());
^
F:\Java\HiLowGame.java:74: cannot find symbol
symbol : variable NORTH
location: class BorderLayout
add(nPanel, BorderLayout.NORTH);
^
Does anybody have any hints after looking at my code below what might be the problem, because I am getting like 15 errors and they all are basically of the same thing.
Java Code:import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.util.Scanner; import java.util.Random; public class HiLowGame extends Applet implements ActionListener { //declares variables Panel nPanel, sPanel, tcPanel, bcPanel, cPanel; Button one; Label top, lb11, lb12, lb13, lb14, bottom; TextField txt; int number, cnumber, count; final int MAX = 25; public void init(){ //create random number Random generator = new Random (); cnumber = generator.nextInt(MAX) +1; //set north panel nPanel = new Panel(); nPanel.setBackground(Color.red); top = new Label("HighLow Game"); //set south panel sPanel = new Panel(); sPanel.setBackground(Color.green); bottom = new Label (""); //set center panel cPanel = new Panel(); tcPanel = new Panel(); bcPanel = new Panel(); one = new Button ("Submit your Guess"); one.addActionListener(this); lb11 = new Label(); lb12 = new Label(); lb13 = new Label(""); txt = new TextField(); lb14 = new Label(""); //set top center GridLayout tcPanel.setLayout(new GridLayout(3,1)); tcPanel.add(lb11); tcPanel.add(one); tcPanel.add(lb12); //set bottom center GridLayout bcPanel.setLayout(new BorderLayout(3,1)); bcPanel.add(lb13); bcPanel.add(txt); bcPanel.add(lb14); //combine tc and bc panels cPanel.setLayout(new BorderLayout()); cPanel.add(tcPanel, BorderLayout.WEST); cPanel.add(bcPanel, BorderLayout.EAST); //set layout and label for top nPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); nPanel.add(top); //set layout and label for bottom sPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); sPanel.add(bottom); //set layout for Applet this.setLayout(new BorderLayout()); add(nPanel, BorderLayout.NORTH); add(cPanel, BorderLayout.CENTER); add(sPanel, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e){ number = Integer.parseInt(txt.getText()); count++; if (number > cnumber) { lb13.setText("Number is too High!"); lb14.setText(""); } else if (number < cnumber) { lb14.setText("Number is too Low!"); lb14.setBackground(Color.blue); lb13.setText(""); } else if (number == cnumber) { bottom.setText("It only took you "+ count +" guesses!"); } } }
-
Do you have another class in your project, a class that you yourself have created, that is named BorderLayout?
- 04-04-2011, 04:52 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
Yes, I do what should I do?
- 04-04-2011, 04:56 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
Ok Now I can actually see my code thanks.
-
Rename it, say to MyBorderLayout. Either that or use the fully qualified class names whenever you need to use either of your two BorderLayout classes:
myPath.BorderLayout (or whatever the path is)
vs
java.awt.BorderLayoutLast edited by Fubarable; 04-04-2011 at 04:59 AM.
- 04-04-2011, 05:43 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
Thanks, Now that since I have a submit button, to add a Clear button in bottom center panel how would I do this because I tried adding this and it interferred with textfield:
P.S. Do I also need to add an actionListener for the Clear button to work?
Java Code:Button one, clear;//////added one = new Button ("Submit your Guess"); one.addActionListener(this); clear = new Button ("Clear");///////////added clear.addActionListener(this);//////////added lb11 = new Label(); lb12 = new Label(); lb13 = new Label(""); txt = new TextField(); lb14 = new Label(""); //set bottom center GridLayout bcPanel.setLayout(new BorderLayout(3,1)); bcPanel.add(lb13); bcPanel.add(txt); bcPanel.add(lb14); bcPanel.add(clear);////////added
- 04-04-2011, 05:58 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
tried making the button smaller but no help:
Java Code:one.setPreferredSize(new Dimension(100,100));
- 04-04-2011, 06:58 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
First Game In Java: Having trouble with my try catch errors.
By Sparkx in forum Java GamingReplies: 2Last Post: 02-19-2011, 06:40 AM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks