Select TextBox on hover
parent
d5bf288c26
commit
948756a1c4
|
@ -66,7 +66,15 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
||||||
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
//player.mousePressed(e);
|
if (hoverCheck(e)) {
|
||||||
|
keyPressed(new KeyEvent(new Component() {
|
||||||
|
}, 0, 0, 0, KeyEvent.VK_ENTER));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addMouseMotionListener(new MouseMotionAdapter() {
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
hoverCheck(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
||||||
|
@ -125,6 +133,17 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hoverCheck(MouseEvent e) {
|
||||||
|
for (TextBox t: textBoxArray) {
|
||||||
|
if (t.isHover(e.getX(), e.getY())) {
|
||||||
|
currentBox = textBoxArray.indexOf(t);
|
||||||
|
System.out.println(t.id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//if a key is pressed, we'll send it over to the Player class for processing
|
//if a key is pressed, we'll send it over to the Player class for processing
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||||
|
|
|
@ -53,4 +53,9 @@ public class TextBox extends Rectangle {
|
||||||
g.setFont(font);
|
g.setFont(font);
|
||||||
drawCenteredTextBox(g, text, backgroundColor, textColor);
|
drawCenteredTextBox(g, text, backgroundColor, textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return this == o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue