Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_03;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.DirectoryIteratorException;
- import java.nio.file.DirectoryStream;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.Vector;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JFileChooser;
- import javax.swing.JFormattedTextField;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPanel;
- import javax.swing.ListSelectionModel;
- import javax.swing.event.ListSelectionEvent;
- import javax.swing.event.ListSelectionListener;
- public class MenuFrame extends JFrame implements ActionListener,ListSelectionListener{
- Board board;
- int sizeOfBoard = 5;
- int winner = 5;
- BoardFrame boardGUI;
- String classesPathString;
- String pathName;
- Paths classesPath;
- private static final long serialVersionUID = 1L;
- JFormattedTextField sizeArea;
- File file;
- Path dir;
- JPanel panel = new JPanel();
- JButton exitButton = new JButton("Exit");
- JButton playButton = new JButton("Play");
- JButton sizeButton = new JButton("Set Size");
- JButton catalogButton = new JButton("Choose Catalog");
- JButton strategyButton = new JButton("Load Strategies");
- JButton levelButton = new JButton("Set Level");
- JButton sampleButton = new JButton("X");
- JLabel sizeLabel = new JLabel("Size of Board");
- JLabel strategyLabel = new JLabel("Strategy:");
- JLabel levelLabel = new JLabel("Dificculty Level:");
- JFileChooser fc = new JFileChooser();
- JList<String> loadedStratedyList = new JList<String>();
- DefaultListModel<String> listStrategyModel = new DefaultListModel<>();
- JList<String> loadedLevelList = new JList<String>();
- DefaultListModel<String> listLevelModel = new DefaultListModel<>();
- Vector<Loader> vectorClass = new Vector<Loader>();
- Vector<String> levelVector = new Vector<String>();
- Vector<String> strategyVector = new Vector<String>();
- public MenuFrame() {
- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- sizeArea = new JFormattedTextField(sizeOfBoard);
- sizeArea.setEditable(true);
- sizeArea.setSize(new Dimension(2,4));
- //JScrollPane sizeScrollPane = new JScrollPane(sizeArea);
- setContentPane(panel);
- loadedStratedyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- loadedStratedyList.addListSelectionListener(this);
- loadedStratedyList.setDragEnabled(true);
- loadedStratedyList = new JList<>(listStrategyModel);
- exitButton.addActionListener(this);
- playButton.addActionListener(this);
- catalogButton.addActionListener(this);
- sizeButton.addActionListener(this);
- strategyButton.addActionListener(this);
- levelButton.addActionListener(this);
- panel.add(sizeLabel);
- panel.add(sizeArea);
- //panel.add(sizeScrollPane);
- panel.add(sizeButton);
- panel.add(catalogButton);
- panel.add(strategyLabel);
- panel.add(loadedStratedyList);
- panel.add(strategyButton);
- panel.add(levelLabel);
- panel.add(levelButton);
- panel.add(playButton);
- panel.add(exitButton);
- setLayout(new FlowLayout(FlowLayout.CENTER));
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(600,650);
- this.setVisible(true);
- }
- public static void main(String[] args) {
- new MenuFrame();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if(source == sizeButton) {
- sizeOfBoard = (int) sizeArea.getValue();
- }
- if(source == catalogButton) {
- int returnVal = fc.showOpenDialog(MenuFrame.this);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- file = fc.getSelectedFile();
- classesPathString = file.getAbsolutePath();
- pathName = file.getPath();
- dir = file.toPath();
- try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
- //Wybór wszystkich podkatalogów danego katalogu
- for (Path filePath: stream) {
- listStrategyModel.addElement(filePath.getFileName().toString());
- strategyVector.addElement(filePath.getFileName().toString());
- }
- } catch (IOException | DirectoryIteratorException x) {
- }
- } else {
- }
- }
- if(source == strategyButton){
- for(int i = 0; i < strategyVector.size(); i++) {
- System.out.println(strategyVector.get(i));
- }
- //System.out.println("Rozmiar" + sizeOfBoard);
- }
- if(source == levelButton) {
- System.out.println(pathName);
- System.out.println(classesPathString);
- }
- if(source == playButton) {
- board = new Board(sizeOfBoard);
- boardGUI = new BoardFrame(sizeOfBoard,strategyVector,levelVector);
- }
- if(source == exitButton) {
- System.exit(0);
- }
- }
- @Override
- public void valueChanged(ListSelectionEvent e) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment