Results 1 to 8 of 8
  1. #1
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default 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!");
    
    	}
    
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Do you have another class in your project, a class that you yourself have created, that is named BorderLayout?

  3. #3
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default

    Yes, I do what should I do?

  4. #4
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default

    Ok Now I can actually see my code thanks.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.BorderLayout
    Last edited by Fubarable; 04-04-2011 at 05:59 AM.

  6. #6
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default

    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

  7. #7
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default

    tried making the button smaller but no help:

    Java Code:
    one.setPreferredSize(new Dimension(100,100));

  8. #8
    Big Bundy is offline Member
    Join Date
    Mar 2011
    Posts
    42
    Rep Power
    0

    Default

    Figured the button, now its just getting it to reset everything. Does anybody know how I would go about reseting all the labels and the textfield back to the start after you finish a game?

Similar Threads

  1. Replies: 2
    Last Post: 02-19-2011, 07:40 AM
  2. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  3. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  4. Replies: 3
    Last Post: 03-08-2009, 02:51 AM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •