Question
1. Study Chapter 3G 2. Sign up repl,it and study the example https://repl.it/join/aydclqoj-xtang 3. Design and implement your own GUI application 4. You can use
1. Study Chapter 3G
2. Sign up repl,it and study the example https://repl.it/join/aydclqoj-xtang
3. Design and implement your own GUI application
4. You can use other IDE such as eclips. Here is the code:
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
/**
* Draws a snowman to demonstrate drawing methods and use of color.
* @author Java Foundations, converted to GUI by mvail
*/
public class Snowman extends JPanel
{
/**
* @param page object on which drawing takes place
*/
public void paintComponent (Graphics page)
{
final int MID = 150;
final int TOP = 50;
page.setColor(Color.CYAN);
page.fillRect(0, 0, getWidth(), getHeight());
Color groundColor = new Color(127, 0, 64);
page.setColor (groundColor);
page.fillRect (0, 175, 300, 50); // ground
page.setColor (Color.yellow);
page.fillOval (-40, -40, 80, 80); // sun
page.setColor (Color.white);
page.fillOval (MID - 20, TOP, 40, 40); // head
page.fillOval (MID - 35, TOP + 35, 70, 50); // upper torso
page.fillOval (MID - 50, TOP + 80, 100, 60); // lower torso
page.setColor (Color.black);
page.fillOval (MID - 10, TOP + 10, 5, 5); // left eye
page.fillOval (MID + 5, TOP + 10, 5, 5); // right eye
page.drawArc (MID - 10, TOP + 20, 20, 10, 190, 160); // smile
page.drawLine (MID - 25, TOP + 60, MID - 50, TOP + 40); // left arm
page.drawLine (MID + 25, TOP + 60, MID + 55, TOP + 60); // right arm
page.drawLine (MID - 20, TOP + 5, MID + 20, TOP + 5); // brim of hat
page.fillRect (MID - 15, TOP - 20, 30, 25); // top of hat
}
/**
* Constructor (panel initialization)
*/
public Snowman()
{
setPreferredSize(new Dimension(300, 200));
}
/**
* Starting point for Snowman application.
* @param args unused
*/
}
public static void main (String[] args)
{
JFrame frame = new JFrame ("Snowman");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new Snowman());
frame.pack();
frame.setVisible(true);
}
Step by Step Solution
3.52 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
1Import the necessary classes 2Create a class that extends JPanel to dra...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started