Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class BoardFace here.
- *
- * @Arjun Bhamra
- * @9/8
- */
- import java.awt.event.MouseListener;
- import java.awt.event.MouseEvent;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Toolkit;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import javax.swing.Timer;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Random;
- import javax.swing.ImageIcon;
- import javax.swing.JPanel;
- import javax.imageio.*;
- import java.awt.image.*;
- import java.io.*;
- import java.util.Scanner;
- public class BoardFace extends JPanel implements Runnable, MouseListener
- {
- private Dimension d;
- int BOARD_WIDTH=500;
- int BOARD_HEIGHT=500;
- int x = 0;
- private Thread animator;
- boolean clicked = false;
- public BoardFace()
- {
- addMouseListener(this);
- setFocusable(true);
- d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT);
- if (animator == null ) {
- animator = new Thread(this);
- animator.start();
- }
- setDoubleBuffered(true);
- }
- public void paint(Graphics g){
- super.paint(g);
- g.setColor(Color.white);
- g.fillRect(0, 0, d.width, d.height);
- //head
- g.setColor(Color.black); // yellow is a field of class Color
- g.fillOval(200,75, 75, 75);
- //feet
- g.setColor(Color.black);// ...so is black...
- g.fillOval(200, 383, 25, 25);
- g.setColor(Color.black);
- g.fillOval(250,383, 25, 25);
- //body
- g.fillRect(200, 165, 75, 130);
- //legs
- g.fillRect(250, 295, 25, 100);
- g.fillRect(200, 295, 25, 100);
- //...& brown can now be used as parameter in method setColor
- //hands and card
- g.fillRect(275, 165, 100, 25);
- g.fillOval(365,165,25, 25);
- g.fillRect(365, 135, 25, 50);
- g.setColor(Color.red);
- // the card
- g.setColor(Color.red);
- if(clicked==true){
- g.setColor(Color.yellow);
- } else {
- g.setColor(Color.red);
- }
- g.fillRect(373, 85, 35, 55);
- g.setColor(Color.black);
- g.fillOval(365, 125, 25, 25);
- //The other hand
- g.fillOval(190, 165, 25, 25);
- g.fillOval(178, 177, 25, 25);
- g.fillOval(166, 189, 25, 25);
- g.fillOval(154, 201, 25, 25);
- g.fillOval(142, 213, 25, 25);
- g.fillOval(130, 225, 25, 25);
- //hat
- /*Color purple= new Color(102,0, 102); //instance variable purple
- g.setColor(purple);
- g.fillRect(75, 75, 375, 50);
- g.fillRect(150, 25, 225, 100);*/
- //writing- keep smiling
- //and to add text to the drawing...
- g.setFont (new Font("TimesRoman", Font.PLAIN, 30));
- g.drawString("Referee Cards:" , 20, 50);
- if(clicked==true){
- g.drawString("Referee Cards: Yellow" , 20, 50);
- }else{
- g.drawString("Referee Cards: Red" , 20, 50);
- }
- Toolkit.getDefaultToolkit().sync();
- g.dispose();
- }
- public void run() {
- long beforeTime, timeDiff, sleep;
- beforeTime = System.currentTimeMillis();
- int animationDelay = 500;
- long time =
- System.currentTimeMillis();
- while (true) {//infinite loop
- // spriteManager.update();
- repaint();
- try {
- time += animationDelay;
- Thread.sleep(Math.max(0,time -
- System.currentTimeMillis()));
- }catch (InterruptedException e) {
- System.out.println(e);
- }//end catch
- }//end while loop
- }//end of run
- public void mousePressed(MouseEvent e) {
- int x = e.getX();
- int y = e.getY();
- if(clicked==false){
- clicked=true;
- } else {
- clicked = false;
- }
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- public void mouseClicked(MouseEvent e) {
- }
- }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement