private void resize() { this.height = entryHeight * graphwar.getGlobalClient().getRooms().size(); if (height < minHeight) { height = minHeight; } this.setPreferredSize(new Dimension(width, height)); this.revalidate(); }
public void mouseReleased(MouseEvent e) { if (graphwar.getGameData().getGameState() == Constants.NONE) { int roomNum = e.getY() / entryHeight; if (roomNum < graphwar.getGlobalClient().getRooms().size()) { Room room = graphwar.getGlobalClient().getRooms().get(roomNum); ((GlobalScreen) graphwar.getUI().getScreen(Constants.GLOBAL_ROOM_SCREEN)) .showMessage("Connecting..."); try { graphwar.joinGame(room.getIp(), room.getPort()); graphwar.getGameData().addPlayer(graphwar.getGlobalClient().getLocalPlayerName()); graphwar.getUI().setScreen(Constants.PRE_GAME_SCREEN); } catch (IOException e1) { ((GlobalScreen) graphwar.getUI().getScreen(Constants.GLOBAL_ROOM_SCREEN)) .showMessage("Could not connect."); graphwar.getGameData().disconnect(); e1.printStackTrace(); } } } }
public void paintComponent(Graphics g) { resize(); g.setColor(Color.WHITE); g.fillRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); g.setColor(Color.BLACK); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setFont(new Font("Sans", Font.BOLD, 14)); ListIterator<Room> itr = graphwar.getGlobalClient().getRooms().listIterator(); int i = 0; while (itr.hasNext()) { Room room = itr.next(); if (roomFocused) { if (focusedRoomNum == i) { g2d.setColor(focusColor); g2d.fillRect(0, entryHeight * i, width, entryHeight); } } g2d.setColor(Color.BLACK); g2d.drawString(" " + room.getName(), 0, entryHeight * (i + 1) - 4); String mode = "y"; if (room.getGameMode() == 1) { mode = "y'"; } else if (room.getGameMode() == 2) { mode = "y''"; } g2d.drawString(mode, width - 40, entryHeight * (i + 1) - 7); g2d.drawString(room.getNumPlayers() + "/10", width - 110, entryHeight * (i + 1) - 6); g2d.drawRect(0, entryHeight * i, width, entryHeight); i++; } }