Пример #1
0
 public Main() {
   dimension = new Dimension(WINDOW_WIDTH * SPRITE_SIZE, WINDOW_HEIGHT * SPRITE_SIZE);
   board = new Board();
   board.setPreferredSize(dimension);
   board.setMinimumSize(dimension);
   initUI();
   pack();
 }
Пример #2
0
 public TetrisWindow(String hostName, int serverPortNumber) throws IOException {
   super("Rainbow Tetris");
   connection = new TetrisClient(hostName, serverPortNumber);
   myID = connection.getID();
   board = new Board();
   message = new JLabel("Waiting for two players to connect.", JLabel.CENTER);
   board.setBackground(Color.WHITE);
   board.setPreferredSize(new Dimension(300, 660));
   board.addMouseListener(
       new MouseAdapter() {
         public void mousePressed(MouseEvent evt) {
           doMouseClick();
         }
       });
   message.setBackground(Color.LIGHT_GRAY);
   message.setOpaque(true);
   JPanel content = new JPanel();
   content.setLayout(new BorderLayout(2, 2));
   content.setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
   content.setBackground(Color.GRAY);
   content.add(board, BorderLayout.CENTER);
   content.add(message, BorderLayout.SOUTH);
   setContentPane(content);
   pack();
   setResizable(false);
   setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           dispose();
           connection.disconnect();
           try {
             Thread.sleep(333);
           } catch (InterruptedException e) {
           }
           System.exit(0);
         }
       });
   setLocation(200, 100);
   setVisible(true);
 }