Advertisement
Guest User

Untitled

a guest
Oct 19th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package projet2;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.GradientPaint;
  7. import java.awt.Graphics;
  8. import java.awt.Graphics2D;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import javax.swing.JButton;
  12.  
  13. public class Bouton extends JButton implements MouseListener{
  14. public Bouton(String str, Color bcolornorm, Color bcolorhover, Color bcolorclic){
  15. super(str);
  16. this.name = str;
  17. this.bcolor = bcolornorm;
  18. this.addMouseListener(this);
  19. }
  20. private String name;
  21. public Color bcolor;
  22. public Color bcolornorm;
  23. public Color bcolorhover;
  24. public Color bcolorclic;
  25.  
  26.  
  27. public void paintComponent(Graphics g){
  28. Graphics2D g2d = (Graphics2D)g;
  29. GradientPaint gp = new GradientPaint(0, 0, Color.blue, 0, 20, Color.cyan, true);
  30. g2d.setPaint(gp);
  31. g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
  32. g2d.setColor(this.bcolor);
  33. g2d.drawString(this.name, this.getWidth() / 2 - (this.getWidth()/ 2 /4), (this.getHeight() / 2) + 5);
  34. }
  35.  
  36. public void mouseClicked(MouseEvent event) {}
  37. public void mouseEntered(MouseEvent event) {
  38. this.bcolor = this.bcolorhover;
  39. }
  40. public void mouseExited(MouseEvent event) {
  41. this.bcolor = this.bcolornorm;
  42. }
  43. public void mousePressed(MouseEvent event) {
  44. this.bcolor = this.bcolorclic;
  45. }
  46. public void mouseReleased(MouseEvent event) {
  47. this.bcolor = this.bcolorhover;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement