Browse Source

Add MouseListener

feature_solitaer_MouseInput
Alexander Hartung 3 years ago
parent
commit
7caebafde9
  1. 60
      src/main/java/solitaer/MyMouseListener.java
  2. 19
      src/main/java/solitaer/SolitaerGamePanel.java

60
src/main/java/solitaer/MyMouseListener.java

@ -0,0 +1,60 @@
package solitaer;
import java.awt.Component;
import java.awt.event.MouseEvent;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;
public class MyMouseListener implements MouseInputListener {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("DOWN");
Component com = SwingUtilities.getDeepestComponentAt(
e.getComponent(), e.getX(), e.getY());
System.out.println("########");
System.out.println(com.toString());
System.out.println(com.getParent().toString());
System.out.println("########");
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}

19
src/main/java/solitaer/SolitaerGamePanel.java

@ -7,17 +7,26 @@ import javax.swing.JPanel;
public class SolitaerGamePanel extends JPanel { public class SolitaerGamePanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private CardDeck deck;
private MyMouseListener mouseL;
public SolitaerGamePanel() { public SolitaerGamePanel() {
setLayout(null); setLayout(null);
mouseL = new MyMouseListener();
this.addMouseListener(mouseL);
deck = new CardDeck();
StartStack a = new StartStack(25,25); StartStack a = new StartStack(25,25);
a.addCard(new Card(13, Symbol.Karo, true));
a.addCard(new Card(1, Symbol.Karo, true));
a.addCard(deck.getDeck().get(0));
deck.getDeck().get(1).setFaceUp(true);
a.addCard((deck.getDeck().get(1)));
this.add(a); this.add(a);
StartStack b = new StartStack(200,25); StartStack b = new StartStack(200,25);

Loading…
Cancel
Save