Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /*
  2. * Bob and his cool nose
  3. *
  4. * Gaileen
  5. *
  6. * 7/4/19
  7. */
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.WindowConstants;
  11. import java.awt.Dimension;
  12. import java.awt.Color;
  13. import java.awt.Graphics;
  14. import java.awt.Graphics2D;
  15. import java.awt.Point;
  16. import java.awt.event.MouseListener;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.Font;
  19. import java.awt.FontMetrics;
  20.  
  21. public class CreativeDraw
  22. {
  23. private JFrame frame;
  24.  
  25. public CreativeDraw()
  26. {
  27. frame = new JFrame("Bob");
  28. frame.setSize(600, 400);
  29. frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  30. frame.setPreferredSize(frame.getSize());
  31. frame.add(new DrawFace(frame.getSize()));
  32. frame.pack();
  33. frame.setVisible(true);
  34. }
  35.  
  36. public static void main(String... argv)
  37. {
  38. new CreativeDraw();
  39. }
  40.  
  41. public static class DrawFace extends JPanel implements MouseListener
  42. {
  43. Color n_color = Color.red;
  44.  
  45. public DrawFace(Dimension dimension)
  46. {
  47. setSize(dimension);
  48. setPreferredSize(dimension);
  49. addMouseListener(this);
  50.  
  51. }
  52.  
  53. @Override
  54. public void paintComponent(Graphics g)
  55. {
  56. Graphics2D g2 = (Graphics2D)g;
  57. Dimension d = getSize();
  58. //background
  59. g2.setColor(Color.blue);
  60. g2.fillRect(0, 0, d.width, d.height);
  61.  
  62.  
  63. //face
  64. g2.setColor(Color.yellow);
  65. g2.fillOval(175,100, 250, 250);
  66.  
  67. //eyes
  68. g2.setColor(Color.black);
  69. g2.fillOval(240,175, 35, 35);
  70. g2.fillOval(320,175, 35, 35);
  71.  
  72. //mouth
  73. g2.setColor(Color.green);
  74. g2.fillOval(250,220, 100, 110);
  75. g2.setColor(Color.yellow);
  76. g2.fillOval(250,200, 100, 110);
  77.  
  78. //nose
  79. g2.setColor(n_color);
  80. g2.fillArc(274,150,50,100,225,90);
  81.  
  82. //display name
  83. g2.setColor(Color.white);
  84. g2.setFont (new Font("TimesRoman", Font.PLAIN, 40));
  85. g2.drawString("Bob" , 40,40);
  86. }
  87.  
  88. public void mousePressed(MouseEvent e) {
  89. Color brown = new Color(102,51, 0);
  90. n_color = brown;
  91.  
  92. repaint();//changes color of nose
  93. }
  94.  
  95. public void mouseReleased(MouseEvent e) {
  96. }
  97.  
  98. public void mouseEntered(MouseEvent e) {
  99. }
  100.  
  101. public void mouseExited(MouseEvent e) {
  102. }
  103.  
  104. public void mouseClicked(MouseEvent e) {
  105.  
  106. }
  107.  
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement