Advertisement
DanielSiqueira

javastuff

Feb 8th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package interfaces;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import javax.swing.JPanel;
  6.  
  7. public class InterfaceController {
  8.     private DFrame currentFrame;
  9.     private JPanel currentInterface;
  10.     private String currentInterfaceName;
  11.     private Map<String,JPanel> interfaces = new HashMap<>();
  12.    
  13.     public InterfaceController(DFrame frame) {
  14.         currentFrame = frame;
  15.     }
  16.    
  17.     public void setCurrentInterface(String UIName) {
  18.         if (this.interfaces.get(UIName) != null) {
  19.             if (this.currentInterface != null) {
  20.                 this.currentInterface.setVisible(false);
  21.             }
  22.             this.currentInterface = this.interfaces.get(UIName);
  23.             this.currentInterfaceName = UIName;
  24.             this.currentInterface.setVisible(true);
  25.         }
  26.     }
  27.    
  28.     public JPanel getCurrentInterface() {
  29.         return this.currentInterface;
  30.     }
  31.    
  32.     public String getCurrentInterfaceName() {
  33.         return this.currentInterfaceName;
  34.     }
  35.    
  36.     public void clearInterfaces() {
  37.         interfaces = new HashMap<>();
  38.         currentInterface = null;
  39.         currentInterfaceName = null;
  40.     }
  41.    
  42.     public void destroyInterface(String UIName) {
  43.         interfaces.remove(UIName);
  44.         if (currentInterfaceName == UIName) {
  45.            
  46.             currentInterface.setVisible(false);
  47.            
  48.             currentInterfaceName = null;
  49.             currentInterface = null;
  50.         }
  51.     }
  52.    
  53.     public void addInterface(String InterfaceName, JPanel Interface) {
  54.         currentFrame.add(Interface);
  55.         interfaces.put(InterfaceName, Interface);
  56.     }
  57.  
  58.     public DFrame getCurrentFrame() {
  59.         return currentFrame;
  60.     }
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement