Neuer Button im WinPanel mit funktion
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@309 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
eb7ccb46c5
commit
794777c2fe
7 changed files with 159 additions and 69 deletions
|
@ -87,7 +87,7 @@ public interface IView {
|
|||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getFinalScoreEvent();
|
||||
public IEvent getEndProgramEvent();
|
||||
|
||||
/**
|
||||
* The new round event is emitted when the player wants to start a new round
|
||||
|
@ -115,4 +115,6 @@ public interface IView {
|
|||
public void setCurrentPlayerColor(Color color);
|
||||
|
||||
public void setHasLaidOut(boolean hasLaidOut);
|
||||
|
||||
IEvent getNewGameEvent();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue