Search:

Type: Posts; User: Norm

Page 1 of 2 1 2

Search: Search took 0.11 seconds.

  1. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Thanks. Makes sense.
  2. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    What's a handler vs a listener?
  3. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Use a different listener for those buttons.
    Or in your actionPerformed() method use the Event getSource() method to get pointer to the button pressed and compare it against the pointers to those two...
  4. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    I have no idea how you've gotten this far.
    I can't begin to explain what you need to know.

    Good luck.
  5. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Better read up on listeners and the event objects that are passed to them.
  6. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    You don't create an event object. The system passes one to the listener.
  7. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Look at post #57
  8. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Yes, evt represents the Event object reference passed to the listener. I didn't look thru your code for correct spelling.
    That object is the one the user clicked on. It could contain its x,y...
  9. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Sounds like you need to debug your system.

    Add lots and lots of: System.out.println("var1= " + var1 + ", var2=" + var2);
    to your code. Change var1, var2 etc as appropriate.
  10. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    What happens?
  11. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Please post the error messages.


    Where do you call placeBattleship()? Is it in the listener that is called every time you hit a button?
    Move it somewhere else.


    Add println() statements to...
  12. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Yes, you should move the assignment statements into one set of loops instead of 3.

    To determine what button was clicked, you need to store some data with the button that has its x,y location.
    Two...
  13. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    How does your program set the values of i and j that you use for indexes?

    What does: e.getActionCommand().equals("0") have to do with the problem?

    What is the value of e.getActionCommand()? ...
  14. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Why not think and compose your question(s) instead of this steady stream of posts?

    ???

    That's because your indexes are both = 0. Where does your code set the values of the indexes to other...
  15. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    arrayOfButtons[i][j] = new JButton("a btn");

    What does that mean? You need to be a bit more specific.
    For example: Can you save a String(or at least a reference to a String) in a JButton object?...
  16. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    That is not a definition. That assigns a value to a variable.

    char[][] arrayOfButtons; // define the variable arrayOfButtons as a 2 dim array of char


    That is a local definition of the...
  17. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Is arrayOfButtons null at line 324?
    Where does the code give arrayOfButtons a value? I mean the class member variable NOT one defined in a method;

    Read up on "scope". A term describing where a...
  18. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Can you post the code around lines 324?
    What variable is at line 324 that is null? What is it null? Where in the code does it set it to a value?
  19. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    When you get errors, please copy and paste the full text of the error message. For large programs copy and paste the section of code around where the error occurs and put a comment on the line...
  20. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Put all variable definitions at the class level so that class methods can see them.

    Not sure what you mean? Are you asking if your code does something? I'd have to see the code to tell you.
  21. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    What? Class level variables are visible in all class methods.

    Do you understand the code I posted? What do the comments in the code say?
  22. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Please post your code in the
    tags to preserve indentations. Your unindented code is AWFUL!

    [code]
    public class Testing {
    int[] anArray; // Define a variable at the class level, outside the...
  23. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    What happens that is not correct? Compiler errors or execution errors?

    Your action listener method should be able to see class member variables.
    Define the two arrays outside of the constructor....
  24. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    No idea what you are saying.
    If an object is defined outside of a method and you pass a reference to an array to the method. There is no reason to return a reference to the same array to the caller....
  25. Replies
    85
    Views
    10,251

    [SOLVED] Re: Battleship GUI Program

    Off the top of my head:


    public int[] returnArray() {
    int[] anArray = new int[5];
    return anArray;
    }


    This is the syntax to return an element of an array. However its missing...
Results 1 to 25 of 29
Page 1 of 2 1 2