F:\java\knim-game\sources\ru\ifmo\knim\screens\StatusPanel.java
|
1 /**
2 * @(#)StatusPanel.java
3 *
4 * Copyright Anthony Yakovlev <yakovlev@rain.ifmo.ru> and Michail Lukin <michail@users.msn.com>
5 */
6
7 package ru.ifmo.knim.screens;
8
9 import java.awt.Font;
10
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JSeparator;
14
15 /**
16 * Status panel with capability to draw separating line & to display text message.
17 * @author Anthony Yakovlev
18 */
19 public class StatusPanel extends JPanel {
20 /**
21 * Storage for last status.
22 */
23 JLabel statusLabel;
24
25 /**
26 * Line, separating this control from uppper content.
27 */
28 JSeparator separator;
29
30 /**
31 * Constructor. Lays out everything and sets sizes.
32 * @param width the desired width of control
33 * @param height the desired height of control
34 */
35 public StatusPanel (int width, int height) {
36 setLayout(null);
37 statusLabel = new JLabel();
38 statusLabel.setLocation(0, 5);
39 statusLabel.setFont(new Font("courier new", Font.PLAIN, 11));
40
41 separator = new JSeparator();
42 separator.setLocation(0, 0);
43
44 setSize(width, height);
45
46 add(statusLabel);
47 add(separator);
48 }
49
50 /**
51 * Updates status of control.
52 * @param text the message to display
53 */
54 public void updateStatus(String text) {
55 statusLabel.setText(text);
56 }
57
58 /**
59 * Resizes status panel.
60 */
61 public void setSize(int width, int height) {
62 statusLabel.setSize(width, height - 5);
63 separator.setSize(width, 5);
64 super.setSize(width, height);
65 }
66 }
67