//board
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;
BufferedImage img;
public BoardFace()
{
addMouseListener(this);
setFocusable(true);
d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT);
try {
img = ImageIO.read(this.getClass().getResource("beard2.png"));
} catch (IOException e) {
System.out.println("Image could not be read");
// System.exit(1);
}
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);
Color brown = new Color(101,0,0);
g.setColor(brown);
g.fillOval(40,10, 450, 350);
//face
g.setColor(Color.blue); // yellow is a field of class Color
g.fillOval(100,100, 350, 330);
//eyes
g.setColor(Color.black);// ...so is black...
g.fillOval(175,175, 80, 50);
g.setColor(Color.black);
g.fillOval(320,175, 80, 50);
Color test = new Color(20,50,80);
g.setColor(test);
g.fillOval(175,175, 50, 30);
g.fillOval(320,175, 50, 30);
//mouth
g.setColor(Color.red);// ...and red.
g.fillOval(190,275, 135, 150);
g.setColor(Color.blue);
g.fillOval(190,250, 175, 125);
g.fillOval(190,250, 175, 125);
g.fillOval(150,250, 175, 125);
//hair
//brown becmones a new instance of the Color class...
//Color brown = new Color(101,0,0);
//...& brown can now be used as parameter in method setColor
g.setColor(brown);
/* g.fillOval(110,100, 75, 75);
g.fillOval(90,80, 75, 75);
g.fillOval(70,60, 75, 75);
g.fillOval(50,40, 75, 75);
g.fillOval(220,55, 75, 75);
g.fillOval(220,40, 75, 55);
g.fillOval(220,30, 75, 35);
// g.fillOval(300,80, 75, 75);
g.fillOval(340,100, 75, 75);
//g.fillOval(380,10, 75, 75);
*/
//nose
//hat
//Color black= new Color(102,80, 152); //instance variable purple
//g.setColor(black);
//g.fillRect(75, 85, 375, 50);
//g.fillRect(150, 25, 25, 100);
//writing- keep smiling
//and to add text to the drawing...
g.setFont (new Font("TimesRoman", Font.PLAIN, 100));
g.drawString("Plz give me an A" , 20, 600);
g.drawImage(img,-20,100,550,584,null);
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();
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
}//end of class
//starter
import javax.swing.JFrame;
public class StarterFace extends JFrame {
public StarterFace()
{
add(new BoardFace());
setTitle("Board");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(700,700);
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
}
public static void main(String[] args) {
new StarterFace();
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.