Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.*;
- import javax.swing.*;
- public class Menu
- {
- /* ATRIBUT */
- JFrame menu = new JFrame("Maze Game");
- JButton open = new JButton("Open");
- JButton choose = new JButton("Choose..");
- ImageIcon img_ic = new ImageIcon("Assets/level/MazePicture.png");
- JLabel maze_img = new JLabel(img_ic);
- JLabel file = new JLabel("Maze text file");
- JTextField fil_pat = new JTextField();
- String address;
- /* CTOR */
- public Menu()
- {
- /* Open file button action listener */
- open.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- new Maze(fil_pat.getText());
- menu.setVisible(false);
- }
- });
- /* Choose maze file button action listener */
- choose.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- JFileChooser fc = new JFileChooser("user.dir");
- int success = fc.showOpenDialog(menu);
- if (success == JFileChooser.APPROVE_OPTION)
- {
- File f = fc.getSelectedFile();
- StringBuilder sb = new StringBuilder(f.getPath());
- int i;
- for (i = sb.length(); i >= 0; i--)
- if (sb.substring(i-1, i).equals("/")) break;
- sb.delete(0, i);
- fil_pat.setText(sb.toString());
- }
- }
- });
- open.setBounds(200, 545, 100, 30);
- file.setBounds(207, 485, 100, 30);
- fil_pat.setBounds(50, 515, 300, 30);
- choose.setBounds(350, 515, 100, 30);
- maze_img.setBounds((500-412)/2, 25, 412, 412);
- menu.add(open);
- menu.add(file);
- menu.add(choose);
- menu.add(fil_pat);
- menu.add(maze_img);
- menu.setBounds(470, 150, 500, 630);
- menu.setLayout(null);
- menu.setVisible(true);
- }
- public static void main(String arg[])
- { new Menu(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement