Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.io.File;
- import javax.swing.*;
- public class Memory extends JFrame {
- final int nPlayers = 2;
- Memory (int size) {
- /* INITIERING */
- File folder = new File("mypictures");
- File[] pictures = folder.listFiles();
- Card[] allCards = new Card[pictures.length];
- for(int i = 0; i < pictures.length; i++) {
- ImageIcon icon = new ImageIcon(pictures[i].getPath());
- allCards[i] = new Card(icon);
- }
- /* LAYOUT */
- GridBagLayout fonster = new GridBagLayout();
- setLayout(fonster);
- GridBagConstraints con;
- // Spelarinfo
- con = new GridBagConstraints();
- con.gridy = 0; con.gridx = 0;
- JPanel players = new JPanel(new GridLayout(nPlayers,1));
- fonster.setConstraints(players, con);
- add(players);
- // Spelplan
- con = new GridBagConstraints();
- con.gridy = 0; con.gridx = 1;
- JPanel game = new JPanel(new GridLayout(size, size));
- fonster.setConstraints(game, con);
- add(game);
- // Kontroll
- con = new GridBagConstraints();
- con.gridy = 1; con.gridx = 0;
- con.gridwidth = 2;
- JPanel control = new JPanel();
- fonster.setConstraints(control, con);
- add(control);
- JButton ny = new JButton("Nytt");
- JButton avsluta = new JButton("Avsluta");
- control.add(ny); control.add(avsluta);
- pack();
- setVisible(true);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- public static void main (String[] arg) {
- String s = JOptionPane.showInputDialog("Storlek på spelplan?");
- int size = Integer.parseInt(s);
- Memory m = new Memory(size);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement