Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import java.awt.*;
  2. import java.io.File;
  3. import javax.swing.*;
  4.  
  5. public class Memory extends JFrame {
  6.     final int nPlayers = 2;
  7.    
  8.     Memory (int size) {
  9.        
  10.         /* INITIERING */
  11.        
  12.         File folder = new File("mypictures");
  13.         File[] pictures = folder.listFiles();
  14.         Card[] allCards = new Card[pictures.length];
  15.         for(int i = 0; i < pictures.length; i++) {
  16.             ImageIcon icon = new ImageIcon(pictures[i].getPath());
  17.             allCards[i] = new Card(icon);
  18.         }
  19.        
  20.         /* LAYOUT */
  21.         GridBagLayout fonster = new GridBagLayout();
  22.         setLayout(fonster);
  23.         GridBagConstraints con;
  24.        
  25.         // Spelarinfo
  26.         con = new GridBagConstraints();
  27.         con.gridy = 0; con.gridx = 0;
  28.         JPanel players = new JPanel(new GridLayout(nPlayers,1));
  29.         fonster.setConstraints(players, con);
  30.         add(players);
  31.        
  32.         // Spelplan
  33.         con = new GridBagConstraints();
  34.         con.gridy = 0; con.gridx = 1;
  35.         JPanel game = new JPanel(new GridLayout(size, size));
  36.         fonster.setConstraints(game, con);
  37.         add(game);
  38.        
  39.         // Kontroll
  40.         con = new GridBagConstraints();
  41.         con.gridy = 1; con.gridx = 0;
  42.         con.gridwidth = 2;
  43.         JPanel control = new JPanel();
  44.         fonster.setConstraints(control, con);
  45.         add(control);
  46.         JButton ny = new JButton("Nytt");
  47.         JButton avsluta = new JButton("Avsluta");
  48.         control.add(ny); control.add(avsluta);
  49.        
  50.         pack();
  51.         setVisible(true);
  52.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  53.     }
  54.     public static void main (String[] arg) {
  55.         String s = JOptionPane.showInputDialog("Storlek på spelplan?");
  56.         int size = Integer.parseInt(s);
  57.         Memory m = new Memory(size);
  58.        
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement