Actually, what I'm going to try and do is create handlers for those two other buttons. That way they won't get null values that screw it up. Then the game will work.
Type: Posts; User: javapenguin
Actually, what I'm going to try and do is create handlers for those two other buttons. That way they won't get null values that screw it up. Then the game will work.
Well, I almost got it to work. The battleship at last is anchored. The setTexts work in the correct spots, but, as I used the same reference variable as I did for the getActionCommand() calls, it...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.Graphics;
...
Part of the code you suggested has made my buttons Quit and Surrender not work as your Point loc thing made them part of it to, but they aren't part of the array.
I'm very tired right now.
...
I got the location thing to work.
Now I'm going to try to get the battleship to stay in one spot and not get lost.
Ok, the compiler errors went away, but it still is only changing 0,0.
What do I do with it now?
Oh, so loc shows which button was clicked.
Also, shouldn't I have to Point classes?
How do...
No, it passes an actionEvent to the listener.
Wait, which is a subclass of EventObject.
#-o#-o^:)^^:)^^:)^
I don't?
So I use the actionEvent variable?
I did.
What goes in the constructor?
EventObject evt = new EventObject();
I tried
Object obj; = new Object();
EventObject evt = new EventObj(ob);
Ok, what kind of Object goes in the constructor?
EventoObject evt = new EventObject();
BattleshipGUI.java:305: cannot find symbol
symbol : constructor EventObject()
location: class...
I never used event object before. I only suspected that as I looked up that method online and it came up in java api as coming from that class, though some classes can have the same method names,...
Ok, the battleship has now, I think, weighed anchor, but it appears to still not be changing after button is pushed. Maybe it's not supposed to. Oh, wait....
public void...
Ok, now the battleship is staying put, but I can never seem to hit it.
So it keeps setting it to 0,0.
I think it's now set so that you can only hit the battleship if you hit it in your first...
It doesn't compile. It's syntax.
Also, battleship still moving. Where should I call it?
In the listener?
In the constructor, where it'll never execute?
Somewhere else?
I have an idea how to do with the moving battleship, even if I have to put it in the listener.
I can't put it sooner or it won't put it at all.
I haven't tried before the constructor but that...
JButton jb = (JButton)evt.getSource();
That doesn't compile.
I've spent a month on this stupid project but I can't give up now. I wish I could get the Battleship to stay put. Where do I...
Well, it'll keep calling placeBattleship every time because GUIs are usually executed more than one till some condition is met.
Is there a way to store the coordinates and set them to that so...
Ok, nearly got it, but how do I get it from calling the method placeBattleship every time I hit a button, thus the battleship keeps moving.
Also, how to I get it i and j to the right values:
...
It's only applying for 0,0 as that's what I initialized it to, but I have no idea how to get it to update according to which button I clicked nor do I know how to keep it from calling the method...
How do I get it so it stops calling place Battleship every time I click a button?
I know what it's doing. i and j are initialized to 0, so it only works for 0, 0.
How do I fix that problem? I've also noticed my battleship is moving.
I need to get it to figure out what button was clicked and get the indexes of those and set them to I and J.
Then it'll work.
But how do you do that?
for ( int i = 0; i < arrayOfButtons.length; i++)
{
for ( int j = 0; j < arrayOfButtons[i].length; j++)
arrayOfButtons[i][j] = new JButton("0");
...
Also, how do you get something to be a parseString?
like Double.parseDouble();
or Integer.parseInt();
What's the one for String?
arrayOfButtons[i][j].setText("H"); // changes text on button to H
arrayOfButtons[i][j].setText("B");
arrayOfButtons[i][j].setText("A"); // changes text on button to A
...