Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. /**
  2. * Write a description of class BoardFace here.
  3. *
  4. * @Arjun Bhamra
  5. * @9/8
  6. */
  7.  
  8. import java.awt.event.MouseListener;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.Color;
  11. import java.awt.Dimension;
  12. import java.awt.Font;
  13. import java.awt.FontMetrics;
  14. import java.awt.Graphics;
  15. import java.awt.Toolkit;
  16. import java.awt.event.KeyAdapter;
  17. import java.awt.event.KeyEvent;
  18. import javax.swing.Timer;
  19. import java.util.ArrayList;
  20. import java.util.Iterator;
  21. import java.util.Random;
  22.  
  23. import javax.swing.ImageIcon;
  24. import javax.swing.JPanel;
  25. import javax.imageio.*;
  26. import java.awt.image.*;
  27. import java.io.*;
  28. import java.util.Scanner;
  29.  
  30.  
  31. public class BoardFace extends JPanel implements Runnable, MouseListener
  32. {
  33.  
  34. private Dimension d;
  35. int BOARD_WIDTH=500;
  36. int BOARD_HEIGHT=500;
  37. int x = 0;
  38. private Thread animator;
  39. boolean clicked = false;
  40.  
  41.  
  42. public BoardFace()
  43. {
  44. addMouseListener(this);
  45. setFocusable(true);
  46. d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT);
  47.  
  48.  
  49. if (animator == null ) {
  50. animator = new Thread(this);
  51. animator.start();
  52. }
  53.  
  54.  
  55. setDoubleBuffered(true);
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62. public void paint(Graphics g){
  63. super.paint(g);
  64.  
  65. g.setColor(Color.white);
  66. g.fillRect(0, 0, d.width, d.height);
  67. //head
  68. g.setColor(Color.black); // yellow is a field of class Color
  69. g.fillOval(200,75, 75, 75);
  70. //feet
  71. g.setColor(Color.black);// ...so is black...
  72. g.fillOval(200, 383, 25, 25);
  73. g.setColor(Color.black);
  74. g.fillOval(250,383, 25, 25);
  75. //body
  76.  
  77. g.fillRect(200, 165, 75, 130);
  78.  
  79. //legs
  80. g.fillRect(250, 295, 25, 100);
  81. g.fillRect(200, 295, 25, 100);
  82. //...& brown can now be used as parameter in method setColor
  83.  
  84. //hands and card
  85. g.fillRect(275, 165, 100, 25);
  86. g.fillOval(365,165,25, 25);
  87. g.fillRect(365, 135, 25, 50);
  88. g.setColor(Color.red);
  89. // the card
  90. g.setColor(Color.red);
  91. if(clicked==true){
  92. g.setColor(Color.yellow);
  93. } else {
  94. g.setColor(Color.red);
  95. }
  96. g.fillRect(373, 85, 35, 55);
  97. g.setColor(Color.black);
  98. g.fillOval(365, 125, 25, 25);
  99.  
  100. //The other hand
  101.  
  102. g.fillOval(190, 165, 25, 25);
  103. g.fillOval(178, 177, 25, 25);
  104. g.fillOval(166, 189, 25, 25);
  105. g.fillOval(154, 201, 25, 25);
  106. g.fillOval(142, 213, 25, 25);
  107. g.fillOval(130, 225, 25, 25);
  108.  
  109.  
  110. //hat
  111. /*Color purple= new Color(102,0, 102); //instance variable purple
  112. g.setColor(purple);
  113. g.fillRect(75, 75, 375, 50);
  114. g.fillRect(150, 25, 225, 100);*/
  115.  
  116. //writing- keep smiling
  117. //and to add text to the drawing...
  118. g.setFont (new Font("TimesRoman", Font.PLAIN, 30));
  119. g.drawString("Referee Cards:" , 20, 50);
  120. if(clicked==true){
  121. g.drawString("Referee Cards: Yellow" , 20, 50);
  122. }else{
  123. g.drawString("Referee Cards: Red" , 20, 50);
  124. }
  125.  
  126.  
  127. Toolkit.getDefaultToolkit().sync();
  128. g.dispose();
  129. }
  130.  
  131.  
  132. public void run() {
  133.  
  134. long beforeTime, timeDiff, sleep;
  135.  
  136. beforeTime = System.currentTimeMillis();
  137. int animationDelay = 500;
  138. long time =
  139. System.currentTimeMillis();
  140. while (true) {//infinite loop
  141. // spriteManager.update();
  142. repaint();
  143. try {
  144. time += animationDelay;
  145. Thread.sleep(Math.max(0,time -
  146. System.currentTimeMillis()));
  147. }catch (InterruptedException e) {
  148. System.out.println(e);
  149. }//end catch
  150. }//end while loop
  151.  
  152.  
  153.  
  154.  
  155. }//end of run
  156.  
  157.  
  158.  
  159. public void mousePressed(MouseEvent e) {
  160. int x = e.getX();
  161. int y = e.getY();
  162.  
  163. if(clicked==false){
  164. clicked=true;
  165. } else {
  166. clicked = false;
  167. }
  168.  
  169.  
  170. }
  171.  
  172. public void mouseReleased(MouseEvent e) {
  173.  
  174. }
  175.  
  176. public void mouseEntered(MouseEvent e) {
  177.  
  178. }
  179.  
  180. public void mouseExited(MouseEvent e) {
  181.  
  182. }
  183.  
  184. public void mouseClicked(MouseEvent e) {
  185.  
  186. }
  187.  
  188. }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement