?? gamestatus.java
字號:
package dungeonsanddragons.game;import dungeonsanddragons.model.Player;import dungeonsanddragons.model.weapons.Weapon;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;/** * Class showing the current game status * @author Sandra Nilsson */public class GameStatus extends JFrame { private JPanel weaponsPanel; private JPanel treasurePanel; private JPanel helthPanel; private JLabel helth; private JLabel weapon; private JLabel treasure; private ImageIcon treasureIcon = new ImageIcon("img/treasure.png"); private ImageIcon healthIcon = new ImageIcon( "img/aid2.png"); /** * Creates a new game status panel */ public GameStatus(){ super("Status Window"); setSize(450,350); init(); } /** * Initializes the contents of the status panel */ private void init(){ JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); helthPanel = new JPanel(); weaponsPanel = new JPanel(); treasurePanel = new JPanel(); helth = new JLabel("0", healthIcon, JLabel.CENTER); weapon= new JLabel("Weapons: "); treasure = new JLabel("0",treasureIcon,JLabel.CENTER); helthPanel.add(helth); weaponsPanel.add(weapon); treasurePanel.add(treasure); mainPanel.add(helthPanel); mainPanel.add(treasurePanel); mainPanel.add(weaponsPanel); this.getContentPane().add(mainPanel); } /** * resets the status information */ public void reset(){ helthPanel.removeAll(); weaponsPanel.removeAll(); treasurePanel.removeAll(); helth = new JLabel("0", healthIcon, JLabel.CENTER); weapon= new JLabel("Weapons: "); treasure = new JLabel("0",treasureIcon,JLabel.CENTER); helthPanel.add(helth); weaponsPanel.add(weapon); treasurePanel.add(treasure); helthPanel.revalidate(); weaponsPanel.revalidate(); treasurePanel.revalidate(); } /** * Updates helth and treasure status for player p * @param p the player to show status for */ public void updateStatus(Player p){ System.out.println("Updating status "); helth.setText(" " + p.getHealthStatus()); treasure.setText(" " + p.getTreasureValue()); } /** * Update the weapons status * @param p the player to show the weapons status for */ public void updateWeapons(Player p){ weaponsPanel.removeAll(); for (Weapon w : p.getWeapons()) { System.out.println("Adding " + w); ImageIcon icon = new ImageIcon(w.getImg()); weaponsPanel.add(new JLabel("Strenght: " + w.getStrenght(),icon, JLabel.CENTER)); } weaponsPanel.revalidate(); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -