//Exam 3 Program
//December 18, 2008
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ShabanExam3 extends Applet
{
public static void main(String[] args)
{
try
{
ObjectInputStream inputStream =
new ObjectInputStream(new FileInputStream("Ornaments.dat"));
int ornamentsX [] = new int [10];
int ornamentsY [] = new int [10];
int ornamentsDiameter [] = new int [10];
for(int count = 0; count < 10; count++)
{
ornamentsX[count] = inputStream.read();
ornamentsY[count] = inputStream.read();
ornamentsDiameter[count] = inputStream.read();
}
}
catch(FileNotFoundException e)
{
System.out.println("Cannot find file Ornaments.dat.");
System.exit(0);
}
catch(IOException e)
{
System.out.println("Problems with input from Ornaments.dat.");
}
}
public static final int WINDOW_WIDTH = 300;
public static final int WINDOW_HEIGHT = 475;
private Color randomColor;
int[] xPoints = {150, 10, 290};
int[] yPoints = {30, 400, 400};
Scanner keyboard = new Scanner(System.in);
public void init()
{
//set the size and background color of itself (the applet)
this.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
this.setBackground(Color.red);
randomColor = new Color((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256));
}
public void paint(Graphics g)
{
g.setColor(new Color(0, 0, 0));
g.fillRect(140, 400, 20, 40);
g.setColor(Color.green);
g.fillPolygon(xPoints, yPoints, 3);
for(int count = 0; count < 10; count++)
{
g.setColor(randomColor);
g.fillOval(ornamentsX, ornamentsY, ornamentsDiameter);
}
}
}
This post has been edited by xxwolfsrainxx: 18 December 2008 - 11:36 AM

New Topic/Question
Reply



MultiQuote




|