Advertisement
Guest User

Untitled

a guest
Mar 31st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.25 KB | None | 0 0
  1. import java.io.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.util.*;
  6. import javax.swing.*;
  7.  
  8. public class Menu
  9. {
  10.     /* ATRIBUT */
  11.     JFrame menu = new JFrame("Maze Game");
  12.     JButton open = new JButton("Open");
  13.     JButton choose = new JButton("Choose..");
  14.     ImageIcon img_ic = new ImageIcon("Assets/level/MazePicture.png");
  15.     JLabel maze_img = new JLabel(img_ic);
  16.     JLabel file = new JLabel("Maze text file");
  17.     JTextField fil_pat = new JTextField();
  18.     String address;
  19.     /* CTOR */
  20.     public Menu()
  21.     {
  22.         /* Open file button action listener */
  23.         open.addActionListener(new ActionListener()
  24.         {
  25.             @Override
  26.             public void actionPerformed(ActionEvent e)
  27.             {
  28.                 new Maze(fil_pat.getText());
  29.                 menu.setVisible(false);
  30.             }
  31.         });
  32.         /* Choose maze file button action listener */
  33.         choose.addActionListener(new ActionListener()
  34.         {
  35.             @Override
  36.             public void actionPerformed(ActionEvent e)
  37.             {
  38.                 JFileChooser fc = new JFileChooser("user.dir");
  39.                 int success = fc.showOpenDialog(menu);
  40.                 if (success == JFileChooser.APPROVE_OPTION)
  41.                 {
  42.                     File f = fc.getSelectedFile();
  43.                     StringBuilder sb = new StringBuilder(f.getPath());
  44.                     int i;
  45.                     for (i = sb.length(); i >= 0; i--)
  46.                         if (sb.substring(i-1, i).equals("/")) break;
  47.                     sb.delete(0, i);
  48.                     fil_pat.setText(sb.toString());
  49.                 }
  50.             }
  51.         });
  52.         open.setBounds(200, 545, 100, 30);
  53.         file.setBounds(207, 485, 100, 30);
  54.         fil_pat.setBounds(50, 515, 300, 30);
  55.         choose.setBounds(350, 515, 100, 30);
  56.         maze_img.setBounds((500-412)/2, 25, 412, 412);
  57.         menu.add(open);
  58.         menu.add(file);
  59.         menu.add(choose);
  60.         menu.add(fil_pat);
  61.         menu.add(maze_img);
  62.         menu.setBounds(470, 150, 500, 630);
  63.         menu.setLayout(null);
  64.         menu.setVisible(true);
  65.     }
  66.  
  67.     public static void main(String arg[])
  68.     { new Menu(); }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement