Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. import java.awt.event.MouseListener;
  2. import java.awt.event.MouseEvent;
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Toolkit;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11. import javax.swing.Timer;
  12. import java.util.ArrayList;
  13. import java.util.Iterator;
  14. import java.util.Random;
  15.  
  16. import javax.swing.ImageIcon;
  17. import javax.swing.JPanel;
  18. import javax.imageio.*;
  19. import java.awt.image.*;
  20. import java.io.*;
  21. import java.util.Scanner;
  22.  
  23. public class BoardFace extends JPanel implements Runnable, MouseListener
  24. {
  25.  
  26. private Dimension d;
  27. int BOARD_WIDTH=500;
  28. int BOARD_HEIGHT=500;
  29. int x = 0;
  30. private Thread animator;
  31. boolean click=false;
  32.  
  33. public BoardFace()
  34. {
  35. addMouseListener(this);
  36. setFocusable(true);
  37. d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT);
  38.  
  39. if (animator == null ) {
  40. animator = new Thread(this);
  41. animator.start();
  42. }
  43.  
  44. setDoubleBuffered(true);
  45. }
  46.  
  47. public void paint(Graphics g){
  48. super.paint(g);
  49.  
  50. g.setColor(Color.white);
  51. g.fillRect(0, 0, d.width, d.height);
  52.  
  53. //brown becmones a new instance of the Color class...
  54. Color brown = new Color(101,0,0);
  55. Color orange = new Color(255,69,0);
  56. Color purple=new Color(250,0,250);
  57.  
  58. g.setColor(Color.black);
  59. //head
  60. g.fillOval(184,100, 160, 160);
  61. //body
  62. g.fillOval(164,180, 200, 250);
  63. //arms
  64. g.fillOval(100,250, 125, 50);
  65. g.fillOval(300,250, 125, 50);
  66.  
  67. //white accents
  68. g.setColor(Color.white);
  69. //stomach
  70. g.fillOval(175,200, 165, 215);
  71. //eyes things
  72. g.fillOval(195,150, 80,80);
  73. g.fillOval(250,150, 80,80);
  74.  
  75. //eyes
  76. g.setColor(Color.black);
  77. g.fillOval(220,170, 15, 25);
  78. g.fillOval(280,170, 15, 25);
  79.  
  80. //pupils
  81. g.setColor(Color.white);
  82. g.fillOval(220,178, 10, 10);
  83. g.fillOval(280,178, 10, 10);
  84.  
  85. //nose and feet
  86. g.setColor(orange);
  87. //nose
  88. g.fillOval(223,200, 70, 30);
  89.  
  90. //feet
  91. g.fillOval(190,410, 60, 30);
  92. g.fillOval(270,410, 60, 30);
  93.  
  94. //click feature
  95. if (click==true){
  96. g.setColor(purple);
  97. g.fillRect(175, 75, 175, 50);
  98. g.fillRect(200, 25, 125, 100);
  99. }
  100.  
  101. //name
  102. g.setColor(Color.black);
  103. g.setFont (new Font("TimesRoman", Font.PLAIN, 25));
  104. g.drawString("Maya Gambhir" , 20, 20);
  105.  
  106. Toolkit.getDefaultToolkit().sync();
  107. g.dispose();
  108. }
  109.  
  110. public void run() {
  111. long beforeTime, timeDiff, sleep;
  112. beforeTime = System.currentTimeMillis();
  113. int animationDelay = 500;
  114. long time =
  115. System.currentTimeMillis();
  116. while (true) {//infinite loop
  117. // spriteManager.update();
  118. repaint();
  119. try {
  120. time += animationDelay;
  121. Thread.sleep(Math.max(0,time -
  122. System.currentTimeMillis()));
  123. }catch (InterruptedException e) {
  124. System.out.println(e);
  125. }//end catch
  126. }//end while loop
  127.  
  128. }//end of run
  129. public void mousePressed(MouseEvent e) {
  130. int x = e.getX();
  131. int y = e.getY();
  132.  
  133. if (click==false){
  134. click=true;
  135. }
  136. else
  137. {click=false;}
  138.  
  139. }
  140.  
  141. public void mouseReleased(MouseEvent e) {
  142.  
  143. }
  144.  
  145. public void mouseEntered(MouseEvent e) {
  146.  
  147. }
  148.  
  149. public void mouseExited(MouseEvent e) {
  150.  
  151. }
  152.  
  153. public void mouseClicked(MouseEvent e) {
  154.  
  155. }
  156.  
  157. }//end of class
  158.  
  159. //end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement