69 lines
1.7 KiB
Java
69 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) {
|
|
jframe.remove(mapselectorpanel);
|
|
jframe.add(gamepanel);
|
|
jframe.revalidate();
|
|
}
|
|
}
|
|
|
|
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);
|
|
gamepanel = new JPanel();
|
|
|
|
jframe.add(mapselectorpanel);
|
|
|
|
// TODO add Ejik's magic to gamepanel
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
jframe.setVisible(true);
|
|
}
|
|
}
|