Page 168 - MDP2022-3
P. 168
@Override
public void mouseExited(MouseEvent e) {
quitButton.setIcon(quitButtonBasicImage);
quitButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
@Override
public void mousePressed(MouseEvent e) {
Music buttonEnteredMusic = new
Music("buttonPressedMusic.mp3" , false);
buttonEnteredMusic.start();
try {
Thread.sleep(1000);
}catch(InterruptedException ex) {
ex.printStackTrace();
}
System.exit(0);
}
});
add(quitButton);
leftButton.setVisible(false);
leftButton.setBounds(600, 550, 60, 60);
leftButton.setBorderPainted(false);
leftButton.setContentAreaFilled(false);
leftButton.setFocusPainted(false);
leftButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
leftButton.setIcon(leftButtonEnteredImage);
leftButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
Music buttonEnteredMusic = new
Music("buttonPressedMusic.mp3" , false);
buttonEnteredMusic.start();
}
@Override
public void mouseExited(MouseEvent e) {
leftButton.setIcon(leftButtonBasicImage);
leftButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
@Override
public void mousePressed(MouseEvent e) {
Music buttonEnteredMusic = new
Music("buttonPressedMusic.mp3" , false);
buttonEnteredMusic.start();