Guest User

Untitled

a guest
Aug 30th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package de.noneatme.littleFighter.classes.guis;
  2.  
  3. import org.newdawn.slick.Color;
  4. import org.newdawn.slick.Font;
  5. import org.newdawn.slick.Graphics;
  6. import org.newdawn.slick.Image;
  7. import org.newdawn.slick.Input;
  8. import org.newdawn.slick.gui.GUIContext;
  9. import org.newdawn.slick.gui.MouseOverArea;
  10. import org.newdawn.slick.util.FontUtils;
  11.  
  12. import de.noneatme.littleFighter.classes.cGameSettings;
  13. import de.noneatme.littleFighter.classes.manager.cFontManager;
  14.  
  15.  
  16. public class BasicButton extends MouseOverArea
  17. {
  18.  
  19.     private String title;
  20.     private Font font;
  21.     private Color fontColor = Color.black;
  22.    
  23.    
  24.     private Image normalImage;
  25.     private Image mouseOverImage;
  26.     @SuppressWarnings("unused")
  27.     private Image mouseDownImage;
  28.    
  29.     public BasicButton(GUIContext container, Font font, int x, int y, int w, int h, String title)
  30.     {
  31.         super(container, null, x, y, w, h);
  32.         this.font       = font;
  33.        
  34.         this.setNormalImage(cGameSettings.imgManager.getImage(1001));
  35.         this.setMouseOverImage(cGameSettings.imgManager.getImage(1002));
  36.         this.setMouseDownImage(cGameSettings.imgManager.getImage(1002));
  37.        
  38.         this.setTitle(title);
  39.     }
  40.  
  41.    
  42.     public void setTitle(String title)
  43.     {
  44.         this.title  = title;
  45.     }
  46.  
  47.     public String getTitle()
  48.     {
  49.         return this.title;
  50.     }
  51.    
  52.     public void setNormalImage(Image img)
  53.     {
  54.         this.normalImage    = img;
  55.     }
  56.    
  57.     public void setMouseOverImage(Image img)
  58.     {
  59.         this.mouseOverImage = img;
  60.     }
  61.    
  62.     public void setMouseDownImage(Image img)
  63.     {
  64.         this.mouseDownImage = img;
  65.     }
  66.    
  67.     public void render(GUIContext cont, Graphics graph)
  68.     {
  69.         Image usedImage;
  70.        
  71.         if(this.isMouseOver())
  72.         {
  73.             usedImage   = this.mouseOverImage;
  74.             this.setFocus(true);
  75.         }
  76.         else
  77.         {
  78.             usedImage   = this.normalImage;
  79.             this.setFocus(false);
  80.         }
  81.        
  82.         graph.drawImage(usedImage.getScaledCopy(this.getWidth(), this.getHeight()), this.getX(), this.getY());
  83.        
  84.         // Text //
  85.         graph.setColor(this.fontColor);
  86.         FontUtils.drawCenter(this.font, this.getTitle(), this.getX(), (this.getY()+(this.getHeight()/2))-cFontManager.BUTTON_FONT.getHeight()/2, this.getWidth());
  87.        
  88.     }
  89.  
  90.     public void mouseClicked(int button, int x, int y, int clickAmmount)
  91.     {
  92.         if(this.hasFocus())
  93.         {
  94.             if(button == Input.MOUSE_LEFT_BUTTON)
  95.             {
  96.                 this.notifyListeners();
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102.  
  103. /*
  104.  *
  105.  *
  106.  * Vornoten: DE 4, EN 3,  Rechnernetze 2, Energiesysteme Bla 4, Datenbanken 2, LF6 1, Mathe 4
  107.  */
Advertisement
Add Comment
Please, Sign In to add comment