Coverage Summary for Class: EndGamePanel (it.polimi.ingsw.Client.GUI.Panels)

Class Class, % Method, % Branch, % Line, %
EndGamePanel 0% (0/1) 0% (0/2) 0% (0/2) 0% (0/33)


1 package it.polimi.ingsw.Client.GUI.Panels; 2  3 import it.polimi.ingsw.Client.GUI.Context; 4 import it.polimi.ingsw.Model.PlayerBoard; 5  6 import javax.swing.*; 7 import java.awt.*; 8 import java.io.IOException; 9 import java.util.List; 10  11 import static it.polimi.ingsw.Client.GUI.IconLoader.sky; 12 import static it.polimi.ingsw.Client.GUI.IconLoader.winnerText; 13  14 /** 15  * Panel showing game's winner(s); it allows user to close the game or join a new lobby 16  */ 17 public class EndGamePanel extends JPanel { 18  19  public EndGamePanel(List<PlayerBoard> playerBoards, Context ctx) { 20  //background label 21  JLabel winnersBackground = new JLabel(sky); 22  winnersBackground.setLayout(null); 23  winnersBackground.setBounds(0, 0, 1080, 720); 24  this.add(winnersBackground); 25  //title's label 26  JLabel WinTitle = new JLabel(winnerText); 27  JLabel winnersNames = new JLabel(); 28  winnersNames.setFont(new Font("Monospaced", Font.BOLD, 22)); 29  //create String containing winner(s)'s names 30  StringBuilder winnersText = new StringBuilder("<html>The winner is/are:<br>"); 31  for (PlayerBoard playerBoard : playerBoards) { 32  winnersText.append(playerBoard.getNickname()); 33  winnersText.append("<br>"); 34  } 35  winnersText.append("</html>"); 36  winnersNames.setText(winnersText.toString()); 37  JButton closeButton = new JButton("Close game"); 38  closeButton.addActionListener(e -> System.exit(0)); 39  JButton startButton = new JButton("Play again"); 40  startButton.addActionListener(e -> { 41  try { 42  ctx.getSocketWrapper().close(); 43  } catch (IOException ex) { 44  throw new RuntimeException(ex); 45  } 46  ctx.getWindow().changeView(new StartPanel(ctx)); 47  }); 48  //---ABSOLUTE POSITIONING--- 49  WinTitle.setBounds(250, 10, 523, 120); 50  winnersNames.setBounds(0, 200, 1080, 150); 51  closeButton.setBounds(350, 450, 130, 65); 52  startButton.setBounds(530, 450, 130, 65); 53  //add components to background label 54  winnersBackground.add(WinTitle); 55  winnersBackground.add(winnersNames); 56  winnersBackground.add(closeButton); 57  winnersBackground.add(startButton); 58  winnersBackground.setOpaque(true); 59  } 60 }