Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Bob and his cool nose
- *
- * Gaileen
- *
- * 7/4/19
- */
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.WindowConstants;
- import java.awt.Dimension;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Point;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseEvent;
- import java.awt.Font;
- import java.awt.FontMetrics;
- public class CreativeDraw
- {
- private JFrame frame;
- public CreativeDraw()
- {
- frame = new JFrame("Bob");
- frame.setSize(600, 400);
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.setPreferredSize(frame.getSize());
- frame.add(new DrawFace(frame.getSize()));
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String... argv)
- {
- new CreativeDraw();
- }
- public static class DrawFace extends JPanel implements MouseListener
- {
- Color n_color = Color.red;
- public DrawFace(Dimension dimension)
- {
- setSize(dimension);
- setPreferredSize(dimension);
- addMouseListener(this);
- }
- @Override
- public void paintComponent(Graphics g)
- {
- Graphics2D g2 = (Graphics2D)g;
- Dimension d = getSize();
- //background
- g2.setColor(Color.blue);
- g2.fillRect(0, 0, d.width, d.height);
- //face
- g2.setColor(Color.yellow);
- g2.fillOval(175,100, 250, 250);
- //eyes
- g2.setColor(Color.black);
- g2.fillOval(240,175, 35, 35);
- g2.fillOval(320,175, 35, 35);
- //mouth
- g2.setColor(Color.green);
- g2.fillOval(250,220, 100, 110);
- g2.setColor(Color.yellow);
- g2.fillOval(250,200, 100, 110);
- //nose
- g2.setColor(n_color);
- g2.fillArc(274,150,50,100,225,90);
- //display name
- g2.setColor(Color.white);
- g2.setFont (new Font("TimesRoman", Font.PLAIN, 40));
- g2.drawString("Bob" , 40,40);
- }
- public void mousePressed(MouseEvent e) {
- Color brown = new Color(102,51, 0);
- n_color = brown;
- repaint();//changes color of nose
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- public void mouseClicked(MouseEvent e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement