Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 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. int check = 1;
  31. private Thread animator;
  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. //background
  50. g.setColor(Color.white);
  51. g.fillRect(0, 0, d.width, d.height);
  52. //penguin body
  53. g.setColor(Color.black);
  54. g.fillOval(170,130, 100, 200);
  55. //arms
  56. g.fillOval(267,200, 15, 80);
  57. g.fillOval(159,200, 15, 80);
  58. //feet
  59. Color orange = new Color(255,128,0);
  60. g.setColor(orange);
  61. g.fillOval(150,315, 60, 15);
  62. g.fillOval(230,315, 60, 15);
  63. //head
  64. g.setColor(Color.black);
  65. g.fillOval(190,100, 60, 60);
  66. //stomach
  67. g.setColor(Color.white);
  68. g.fillOval(185,169, 60, 120);
  69. //beak
  70. g.setColor(orange);
  71. g.fillRect(225, 130, 50, 10);
  72.  
  73. if(check % 2 == 0) {
  74. //top hat
  75. g.setColor(Color.black);
  76. g.fillRect(200, 60, 30, 40);
  77. g.fillRect(180, 100, 70, 15);
  78. Color purple= new Color(102,0, 102);
  79. g.setColor(purple);
  80. g.fillRect(200, 93, 30, 8);
  81. }
  82. g.setColor(Color.red);
  83. g.setFont (new Font("TimesRoman", Font.PLAIN, 50));
  84. g.drawString("Surprise Penguin" , 20, 400);
  85.  
  86. Toolkit.getDefaultToolkit().sync();
  87. g.dispose();
  88. }
  89.  
  90. public void run() {
  91. long beforeTime, timeDiff, sleep;
  92. beforeTime = System.currentTimeMillis();
  93. int animationDelay = 500;
  94. long time =
  95. System.currentTimeMillis();
  96. while (true) {//infinite loop
  97. // spriteManager.update();
  98. repaint();
  99. try {
  100. time += animationDelay;
  101. Thread.sleep(Math.max(0,time -
  102. System.currentTimeMillis()));
  103. }catch (InterruptedException e) {
  104. System.out.println(e);
  105. }//end catch
  106. }//end while loop
  107.  
  108. }//end of run
  109. public void mousePressed(MouseEvent e) {
  110. int x = e.getX();
  111. int y = e.getY();
  112. check++;
  113. }
  114.  
  115. public void mouseReleased(MouseEvent e) {
  116. }
  117.  
  118. public void mouseEntered(MouseEvent e) {
  119. }
  120.  
  121. public void mouseExited(MouseEvent e) {
  122. }
  123.  
  124. public void mouseClicked(MouseEvent e) {
  125. }
  126. }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement