66 lines
1.7 KiB
Java
66 lines
1.7 KiB
Java
package cicaprojekt;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
import java.awt.*;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.io.File;
|
|
|
|
public class ApplicationFrame implements Runnable
|
|
{
|
|
private Game game;
|
|
|
|
private JFrame jframe;
|
|
|
|
private JPanel mapselectorpanel;
|
|
private JPanel gamepanel;
|
|
|
|
private JList<File> filelist;
|
|
|
|
|
|
public ApplicationFrame(Game game){
|
|
this.game = game;
|
|
}
|
|
|
|
private class ListMouseHandler extends MouseAdapter{
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
JOptionPane.showMessageDialog(null, ((JList<File>)e.getComponent()).getSelectedValue().toString());
|
|
}
|
|
}
|
|
|
|
public void init(){
|
|
jframe = new JFrame();
|
|
jframe.setMinimumSize(new Dimension(600, 400));
|
|
|
|
mapselectorpanel = new JPanel();
|
|
|
|
DefaultListModel<File> dungeonslist = new DefaultListModel<>();
|
|
File dir = new File(System.getProperty("user.dir"));
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("N/A", "dungeon");
|
|
|
|
for (File f : dir.listFiles()) {
|
|
if (filter.accept(f) && f.isFile()){
|
|
dungeonslist.addElement(f);
|
|
}
|
|
}
|
|
|
|
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
|
|
public void run() {
|
|
jframe.setVisible(true);
|
|
}
|
|
}
|