From 22553d657ffdc9285ed99776b7e7e4b5cf80881c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sat, 7 May 2016 17:07:27 +0200 Subject: [PATCH] added proof of concept mouse listener to JList in ApplicationFrame --- cicaprojekt/ApplicationFrame.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cicaprojekt/ApplicationFrame.java b/cicaprojekt/ApplicationFrame.java index 89e0151..4d8f84c 100644 --- a/cicaprojekt/ApplicationFrame.java +++ b/cicaprojekt/ApplicationFrame.java @@ -4,6 +4,8 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -20,6 +22,13 @@ public class ApplicationFrame implements Runnable public ApplicationFrame(){} + private class ListMouseHandler extends MouseAdapter{ + @Override + public void mouseClicked(MouseEvent e) { + JOptionPane.showMessageDialog(null, ((JList)e.getComponent()).getSelectedValue().toString()); + } + } + public void init(){ jframe = new JFrame(); jframe.setMinimumSize(new Dimension(600, 400)); @@ -39,10 +48,13 @@ public class ApplicationFrame implements Runnable filelist = new JList<>(dungeonslist); filelist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); filelist.setLayoutOrientation(JList.HORIZONTAL_WRAP); + filelist.addMouseListener(new ListMouseHandler()); mapselectorpanel.add(filelist); jframe.add(mapselectorpanel); + + //TODO rewrite demo ListMouseHandler and do Game stuff... } @Override