From 794777c2fe8808444d2952d8abe287278d81f119 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sun, 29 May 2011 20:19:17 +0200 Subject: Neuer Button im WinPanel mit funktion git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@309 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/View.java | 10 +++++-- src/jrummikub/view/impl/WinPanel.java | 52 +++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 17 deletions(-) (limited to 'src/jrummikub/view/impl') diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 184155f..b2ae7fb 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -205,7 +205,13 @@ public class View extends JFrame implements IView { } @Override - public IEvent getFinalScoreEvent() { - return winPanel.getFinalScoreEvent(); + public IEvent getNewGameEvent() { + return winPanel.getNewGameEvent(); } + + @Override + public IEvent getEndProgramEvent() { + return winPanel.getEndProgramEvent(); + } + } diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java index 13a7eb4..61f6e05 100644 --- a/src/jrummikub/view/impl/WinPanel.java +++ b/src/jrummikub/view/impl/WinPanel.java @@ -27,9 +27,11 @@ class WinPanel extends JPanel { private JLabel winLabel; private JButton newRoundButton; - private JButton finalScoreButton; + private JButton newGameButton; + private JButton endProgramButton; - private Event finalScoreEvent = new Event(); + private Event endProgramEvent = new Event(); + private Event newGameEvent = new Event(); private Event newRoundEvent = new Event(); /** @@ -56,14 +58,23 @@ class WinPanel extends JPanel { }); add(newRoundButton); - finalScoreButton = new JButton("Endauswertung"); - finalScoreButton.addActionListener(new ActionListener() { + newGameButton = new JButton("Neues Spiel"); + newGameButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - finalScoreEvent.emit(); + newGameEvent.emit(); } }); - add(finalScoreButton); + add(newGameButton); + + endProgramButton = new JButton("Programm verlassen"); + endProgramButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + endProgramEvent.emit(); + } + }); + add(endProgramButton); addComponentListener(new ComponentAdapter() { @Override @@ -77,7 +88,7 @@ class WinPanel extends JPanel { * Sets the name of the current player * * @param name - * the player name + * the player name */ void setCurrentPlayerName(String name) { winLabel.setText("Du hast gewonnen, " + name + "!"); @@ -92,19 +103,24 @@ class WinPanel extends JPanel { return newRoundEvent; } + IEvent getNewGameEvent() { + return newGameEvent; + } + /** - * The quit event is emitted when the player wants to quit the program + * The end program is emitted when the player wants to quit the program * * @return the event */ - IEvent getFinalScoreEvent() { - return finalScoreEvent; + IEvent getEndProgramEvent() { + return endProgramEvent; } private void rescale() { Insets insets = getInsets(); int x = insets.left, y = insets.top, width = getWidth() - insets.left - - insets.right, height = getHeight() - insets.top - insets.bottom; + - insets.right, height = getHeight() - insets.top + - insets.bottom; if (width > PANEL_MAX_WIDTH) { x += (width - PANEL_MAX_WIDTH) / 4; @@ -112,7 +128,7 @@ class WinPanel extends JPanel { } int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT); - int buttonWidth = (width - PANEL_SEPARATOR) / 2; + int buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3; int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight; float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; if (fontSize > MAX_BUTTON_FONT_SIZE) @@ -123,8 +139,14 @@ class WinPanel extends JPanel { buttonWidth, buttonHeight); newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); - finalScoreButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y + firstLineHeight - + PANEL_SEPARATOR, buttonWidth, buttonHeight); - finalScoreButton.setFont(finalScoreButton.getFont().deriveFont(fontSize)); + newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y + + firstLineHeight + PANEL_SEPARATOR, buttonWidth, buttonHeight); + newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); + + endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), y + + firstLineHeight + PANEL_SEPARATOR, buttonWidth, buttonHeight); + endProgramButton.setFont(endProgramButton.getFont() + .deriveFont(fontSize)); + } } -- cgit v1.2.3