klasscho

GuiScreen

Jun 8th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package com.gui;
  2.  
  3.  
  4. import java.awt.*;
  5. import java.awt.event.MouseEvent;
  6. import java.util.HashMap;
  7.  
  8. public class GuiScreen {
  9.     private static GuiScreen screen;
  10.     private HashMap<String, GuiPanel> panels = new HashMap<>();
  11.     private String currentPanel = "";
  12.  
  13.     private GuiScreen(){}
  14.  
  15.     public static GuiScreen getInstance(){
  16.         if (screen == null){
  17.             screen = new GuiScreen();
  18.         }
  19.         return screen;
  20.     }
  21.  
  22.     public void update(){
  23.         if (this.panels.get(this.currentPanel) != null){
  24.             ((GuiPanel)this.panels.get(this.currentPanel)).update();
  25.         }
  26.     }
  27.  
  28.     public void render(Graphics2D g){
  29.         if (this.panels.get(this.currentPanel) != null){
  30.             ((GuiPanel)this.panels.get(this.currentPanel)).render(g);
  31.         }
  32.     }
  33.  
  34.     public void add(String panelName, GuiPanel panel){
  35.        this.panels.put(panelName, panel);
  36.     }
  37.  
  38.     public void setCurrentPanel(String panelName){
  39.         this.currentPanel = panelName;
  40.     }
  41.  
  42.     public void mousePressed(MouseEvent e){
  43.         if (this.panels.get(this.currentPanel) != null){
  44.             ((GuiPanel)this.panels.get(this.currentPanel)).mousePressed(e);
  45.         }
  46.     }
  47.  
  48.     public void mouseReleased(MouseEvent e){
  49.         if (this.panels.get(this.currentPanel) != null) {
  50.             ((GuiPanel)this.panels.get(this.currentPanel)).mouseReleased(e);
  51.         }
  52.     }
  53.  
  54.     public void mouseDragged(MouseEvent e){
  55.         if (this.panels.get(this.currentPanel) != null) {
  56.             ((GuiPanel)this.panels.get(this.currentPanel)).mouseDragged(e);
  57.         }
  58.     }
  59.  
  60.     public void mouseMoved(MouseEvent e){
  61.         if (this.panels.get(this.currentPanel) != null) {
  62.             ((GuiPanel)this.panels.get(this.currentPanel)).mouseMoved(e);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment