Hi, I'm new to Java programming and I am still learning the basics. I have been asked to make a hexagon grid for an assignment at school. I managed to create the grid, and the hexagons are aware of their neighbors. Now I am trying to put a picture of a door,arrow, and light bulb inside some of the hexagons but not all of them. When I click on the light bulb I want some of the surrounding hexagons to turn yellow and when I click on the bulb again I want the surrounding hexagons to turn back to white(the default color). The door and arrow functions will not serve any purpose yet so Im not concern with them. So the question is, how do I do all this?
@Override
public void mouseClicked(MouseEvent e) {
String message= String.format("Mouse clicked on hex(%d,%d)",row,col);
JOptionPane.showMessageDialog(null,message);
}
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
});
}
public void addNeighbors(HexDirection dir, Hexagons hex){
neighbors.set(dir.getInt(), hex);
}
public Hexagons getNeighbors(HexDirection dir){
return neighbors.get(dir.getInt());
}
private int row;
private int col;
private HexMap map;
private int width;
private int height;
private ArrayList<Hexagons>neighbors;
}
Lastly I have a shape class which have the door, arrow, and bulb images(the code for this class is incomplete:
package hexagon.project;
import acm.graphics.GImage;
public class Shapes {
public Shapes(int width, int height){
GImage door = new GImage("door.bmp");
etc...
}
GImage leftArrow;
GImage rightArrow;
GImage door;
P.S my grid is a 13x13 grid. It also should tell you which one you clicked based on the row and col, although I can't seem to get it to display a dialog message that says anything but row 13, col 13
It also should tell you which one you clicked based on the row and col, although I can't seem to get it to display a dialog message that says anything but row 13, col 13
Code:
Hexagons hex = new Hexagons(this, rows, cols, hexWidth, hexHeight);
should be:
Code:
Hexagons hex = new Hexagons(this, row, col, hexWidth, hexHeight);
Bookmarks