Question
Part I: Study and run the program: Snowman.java from Chapter 2, page 102. Hint: Snowman.java is an Applet which means it should be embedded to
Part I:
Study and run the program: Snowman.java from Chapter 2, page 102.
Hint: Snowman.java is an Applet which means it should be embedded to a web-browser. In this class we can use a utility to run Applets. Following the steps to run the original snowman:
- Save the Snowman.java into a directory of your desire. For example, I save mine in C:\Temp directory
- Create a file: Snowman.html with two lines in it and save it to C:\Temp
- At the command prompt, type cd C:\Tempd.
- At the command prompt, type dir. You should see both Snowman.java and Snowman.html in there
- At the command prompt, type javac Snowman.javaf.At the command prompt, type appletviewer Snowman.htmlthe snowman should be displayed in a small window.
Your task:
- Modify theopening program descriptions (comments)so that it include:
- The file name including full pathname. Ex: C:\Temp\Snowman.java
- The programmers name(your name)
- The Due dated.
- The description of the purpose of this program
- Change the color of snowmans head and ground to random colors
- Change the class name to Snowman_firstInitialLastNameand the correspondent file name.Important: the code=Snowman in item b is the class name. If you changed your class name to include your first initialand last name, you should change this line in the .html file as well.
Part II:
Use the Graphics, Color and Font objects to construct a picture with shapesof your design.You will be graded by the design, color, and documentation.You design must include the followings:
1. at least 3 different basic shapes
2. at least 2 different none-basic colorswhich including one that uses Random number to generate color components. Indicate which shape has random color in your opening program description.
3. your full name must shown in the output screen
4. the complexity of your design should be compatible to the attached sample files.
5. The program indentation must be correct.
6. The filename need be include your firstInitialLastName in it. The file name should reflect to your drawing too.
You can draw your shapes in a regular JPanel or you can draw them in an applet. Use the sample programs attached-Fishtank.java and Fishtank.htmfor JApplet graphicsand Tutle.java for the stand along window graphics. In order to draw shapes in an applet, you need construct two files: a java program which draw the picture of your design and a .html file which invokes the java class of your design. The you need compile the java program and view the html file using : a:\appletviewer xxx.htmlA good design with effort is expected from each of you in order to get a full marks for this assignment.
Submit:
1.Snowman_firstInitialLastName.java
2.Snowman_firstInitialLastName.html
3.yourGraph_firstInitalLastName.java
4.yourGraph_firstInitalLastName.htmlsubmit this only if you are writing an applet.
Snowman.java
//******************************************************************** // Snowman.java Author: Lewis/Loftus // // Demonstrates basic drawing methods and the use of color. //********************************************************************
import javax.swing.JApplet; import java.awt.*;
public class Snowman extends JApplet { //----------------------------------------------------------------- // Draws a snowman. //----------------------------------------------------------------- public void paint(Graphics page) { final int MID = 150; final int TOP = 50;
setBackground(Color.cyan);
page.setColor(Color.blue); 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 } }
Picture.java
/* * Created on Nov 10, 2005 * Due Nov 12, 2005 * @author Douglas Jones * * Program description: This program demonstrates the usage of JPanels * and the graphics class. The JPanel is the canvas for the picture, * while the graphics class draws the shapes, and produces the colors. * The program draws five stars which are represented by the five int * arrays and the corresponding drawPolygon method calls. The main part * of the picture are the greek letters. They are layered to produce the * outline and the open parts of the phi and the theta. The picture uses * two different fonts the first for the main text is a cursive script * and the second and bolder font for the number 3. There is a triangle * on the side of the greek letters. The colors are created either using * various RGB combinations or the colors included in the graphics class. */ import javax.swing.JFrame;
public class picture { public static void main(String[] args) { JFrame frame = new JFrame("My Letters"); // creates a new frame frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); letters panel = new letters();//creates a new panel in the frame frame.getContentPane().add(panel);//add the panel to the frame frame.pack(); frame.setVisible(true);//makes the frame visible } }
Turtle.java
// //CSC 295 //
// Using javax.swing, this program creates a turtle, music notes, moon, butterfly graphic
import javax.swing.*; //for JFrame import java.awt.*; //for Graphics and Container
public class Turtle {
public static void main( String[] args ) { JFrame win = new JFrame("Graphic Picture"); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.getContentPane().add(new TurtlePanel()); win.setSize(1000,675); win.setLocation(100,100); win.setVisible(true);
} } class TurtlePanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(new Color(0,0,51));//sets background color /******* CREATE SUN ******* */ g.setColor(new Color(255,255,204));//sets color for sun g.fillOval(26,30,175,175);//creates sun /******* CREATE GROUNDS ******* */ g.setColor(new Color(0,153,0));//sets color for ground g.fillRect(0,494,1000,181);//creates ground /******* CREATE MUSIC NOTES ******* */ g.setColor(new Color(204,0,204));//sets color of music notes
g.fillOval(100,394,20,19);//creates music notes num 1 g.fillOval(135,394,20,19);//creates music notes num 1 g.drawLine(117,360,117,397);//Draws Line g.drawLine(152,360,152,397); g.drawLine(117,360,152,360); g.setColor(new Color(255,153,0));// sets color of music note num 2 g.fillOval(63,335,20,19);//creates music notes num 2 g.drawLine(80,307,80,339);//Draws Line g.setColor(new Color(255,051,102));//sets color of music note number 3 g.fillOval(383,234,20,19);//creates music notes num 3 g.fillOval(418,234,20,19);//creates music notes num 3 g.drawLine(400,200,400,250); g.drawLine(435,200,435,250); g.drawLine(400,200,435,200); g.setColor(new Color(0,102,204));//sets color of music notes 4 g.fillOval(640,213,20,19);//creates music notes num 4 g.drawLine(642,216,642,265);//Draws Line g.setColor(new Color(255,0,204));// sets color of music note num 5 g.fillOval(883,423,20,19);//creates music notes num 5 g.drawLine(885,426,885,475);//Draws Line
/* ********CREATE TURTLE******* */ g.setColor(new Color(102,153,0)); g.fillArc(400,320,290,280,-180,-180);// make turtle body g.fillOval(665,340,120,120);//creates turtle head g.fillOval(430,450,70,45);//creates feet g.fillOval(590,450,70,45);//creates feet g.setColor(Color.white); g.fillOval(740,360,30,30);//creates turtle eye g.setColor(Color.black); g.fillOval(756,365,15,15);//creates turtle eyeball g.drawArc(740,400,41,30,180,180);// makes turtle smile g.setColor(new Color(204,255,0)); g.fillArc(430,340,230,200,-180,-180);// make turtle inner body /* ********CREATE CLOUDS******* */ g.setColor(new Color(204,204,255)); g.fillOval(415,43,100,50); g.fillOval(495,53,100,50); g.fillOval(445,63,80,50); g.fillOval(715,83,100,50); g.fillOval(795,93,100,50); g.fillOval(745,103,80,50); g.fillOval(215,83,100,50); g.fillOval(295,93,100,50); g.fillOval(245,103,80,50); /* ********CREATE BUTTERFLY******* */ g.setColor(new Color(153,0,102)); g.fillOval(836,225,28,28);//creates butterfly wing g.fillOval(808,225,28,28);//creates butterfly wing g.setColor(new Color(204,102,153)); g.fillOval(836,250,28,28);//creates butterfly wing g.fillOval(808,250,28,28);//creates butterfly wing g.setColor(new Color(102,053,0));// creates butterfly body g.fillOval(826,220,18,60);//creates butterfly body /* *******CREATE String********* */ g.setFont (new Font("Elegance",Font.ITALIC, 36));//the default font g.setColor(new Color(102,0,102));// creates butterfly body g.drawString("Brendina Rogers", 600, 575); //Used to display name
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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