1 package khumpangame; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import javax.swing.border.*; 7 8 12 public class MoveApp extends JFrame 13 { 14 private final Model model = new Model(); 15 private final MoveView view = new MoveView(model, 50, true); 16 17 19 public MoveApp(boolean standalone) 20 { 21 super("Khun Pan Game"); 22 this.setResizable(false); 23 if(standalone) 24 { 25 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 26 } 27 28 JTextArea explainArea = new JTextArea("The goal is to move the blocs below\r\nto reach the end position\r\ndepicted on the right."); 30 JPanel explainPanel = new JPanel(new BorderLayout()); 31 explainPanel.setBorder(new EmptyBorder(2,2,2,4)); 32 explainPanel.add(explainArea, BorderLayout.CENTER); 33 explainArea.setBackground(this.getBackground()); 34 explainArea.setEditable(false); 35 explainArea.setBorder(new EmptyBorder(5,5,5,5)); 36 Model endModel = new Model(Model.standardProblemEndPosition, Model.standardProblemEndPosition); MoveView endView = new MoveView(endModel, 8, false); 38 explainPanel.add(endView, BorderLayout.EAST); 39 this.getContentPane().add(explainPanel, BorderLayout.NORTH); 40 41 view.setAlignmentX(JComponent.CENTER_ALIGNMENT); 43 this.getContentPane().add(view, BorderLayout.CENTER); 44 45 JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 46 this.getContentPane().add(controlPanel, BorderLayout.SOUTH); 47 JButton reset = new JButton("Reset"); 48 controlPanel.add(reset); 49 reset.addActionListener(new ActionListener() 50 { 51 public void actionPerformed(ActionEvent ae) 52 { 53 model.reset(); 54 view.repaint(); 55 } 56 }); 57 58 pack(); 59 this.setLocationRelativeTo(null); 60 this.setVisible(true); 61 } 63 64 65 public static void main(String [] args) 66 { 67 new MoveApp(true); 68 } 69 70 71 72 } | Popular Tags |