travist120
May 26th, 2008, 12:56 AM
Hey all, I'm having trouble, I'm wondering why the screensaver suddenly stops working when it hits a specific point on the screen. It's a school project so please bear with the noobness of the program.
//L7_ScreenSaver2 by Travis Moore
// Period 1
// This is a seperate project screensaver that draws lines that bounce off the edges of the screens.
// and a second line follows up to cover it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
public class L7_ScreenSaver2 extends JFrame {
public static final int NOTHING = 0;
public static final int TOP = 1;
public static final int RIGHT = 2;
public static final int BOTTOM = 3;
public static final int LEFT = 4;
public static final int DRAW = 1;
public static final int ERASE = 2;
public L7_ScreenSaver2 () {
super("Graphics Window");
Container container = getContentPane();
// these numbers are the width and height of our window
// if you want a bigger window, change the numbers
setSize(1020, 720);
setVisible(true);
}
public void paint(Graphics g) {
int across = 500, down = 500, secondAcross = 0, secondDown = 0, whichBall = NOTHING;
int windowHorizantal = 0, windowVerticle = 0;
int goDown = 1, goAcross = 1, areaHIT = NOTHING, randColor = 0, eraseDown = 1, eraseAcross = 1;
Color currentColor = Color.blue;
windowHorizantal = 1020;
windowVerticle = 720;
//Begin
g.setColor(Color.black);
g.fillRect(1, 1, windowHorizantal, windowVerticle);
while (true) {
if (whichBall == DRAW){
randColor = (int)(Math.random() * 6) + 1;
}
if (randColor == 1){
currentColor = Color.red;
}
if (randColor == 2){
currentColor = Color.blue;
}
if (randColor == 3){
currentColor = Color.green;
}
if (randColor == 4){
currentColor = Color.white;
}
if (randColor == 5){
currentColor = Color.yellow;
}
if (randColor == 6){
currentColor = Color.magenta;
}
if (areaHIT == TOP){
if (whichBall == DRAW){
goDown = 1;
}
if (whichBall == ERASE){
eraseDown = 1;
}
}
if (areaHIT == RIGHT){
if (whichBall == DRAW){
goAcross = -1;
}
if (whichBall == ERASE){
eraseAcross = -1;
}
}
if (areaHIT == BOTTOM){
if (whichBall == DRAW){
goDown = -1;
}
if (whichBall == ERASE){
eraseDown = -1;
}
}
if (areaHIT == LEFT){
if (whichBall == DRAW){
goAcross = 1;
}
if (whichBall == ERASE){
eraseAcross = 1;
}
}
areaHIT = NOTHING;
randColor = 0;
while (areaHIT == NOTHING){
if (across == 5){
areaHIT = LEFT;
whichBall = DRAW;
}
if (across == 1010){
areaHIT = RIGHT;
whichBall = DRAW;
}
if (down == 30){
areaHIT = TOP;
whichBall = DRAW;
}
if (down == 710){
areaHIT = BOTTOM;
whichBall = DRAW;
}
if (secondAcross == 5){
areaHIT = LEFT;
whichBall = ERASE;
}
if (secondAcross == 1010){
areaHIT = RIGHT;
whichBall = ERASE;
}
if (secondDown == 30){
areaHIT = TOP;
whichBall = ERASE;
}
if (secondDown == 710){
areaHIT = BOTTOM;
whichBall = ERASE;
}
across = across + goAcross;
down = down + goDown;
secondAcross = secondAcross + eraseAcross;
secondDown = secondDown + eraseDown;
g.setColor(currentColor);
g.fillOval(across, down, 5, 5);
g.setColor(Color.black);
g.fillOval(secondAcross, secondDown, 5, 5);
delay(10);
}
}
}
public void delay(int p) {
try {
Thread.sleep(p);
}
catch (InterruptedException e) {
}
}
public static void main(String[] args) {
L7_ScreenSaver2 prog = new L7_ScreenSaver2 ();
prog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}
//L7_ScreenSaver2 by Travis Moore
// Period 1
// This is a seperate project screensaver that draws lines that bounce off the edges of the screens.
// and a second line follows up to cover it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
public class L7_ScreenSaver2 extends JFrame {
public static final int NOTHING = 0;
public static final int TOP = 1;
public static final int RIGHT = 2;
public static final int BOTTOM = 3;
public static final int LEFT = 4;
public static final int DRAW = 1;
public static final int ERASE = 2;
public L7_ScreenSaver2 () {
super("Graphics Window");
Container container = getContentPane();
// these numbers are the width and height of our window
// if you want a bigger window, change the numbers
setSize(1020, 720);
setVisible(true);
}
public void paint(Graphics g) {
int across = 500, down = 500, secondAcross = 0, secondDown = 0, whichBall = NOTHING;
int windowHorizantal = 0, windowVerticle = 0;
int goDown = 1, goAcross = 1, areaHIT = NOTHING, randColor = 0, eraseDown = 1, eraseAcross = 1;
Color currentColor = Color.blue;
windowHorizantal = 1020;
windowVerticle = 720;
//Begin
g.setColor(Color.black);
g.fillRect(1, 1, windowHorizantal, windowVerticle);
while (true) {
if (whichBall == DRAW){
randColor = (int)(Math.random() * 6) + 1;
}
if (randColor == 1){
currentColor = Color.red;
}
if (randColor == 2){
currentColor = Color.blue;
}
if (randColor == 3){
currentColor = Color.green;
}
if (randColor == 4){
currentColor = Color.white;
}
if (randColor == 5){
currentColor = Color.yellow;
}
if (randColor == 6){
currentColor = Color.magenta;
}
if (areaHIT == TOP){
if (whichBall == DRAW){
goDown = 1;
}
if (whichBall == ERASE){
eraseDown = 1;
}
}
if (areaHIT == RIGHT){
if (whichBall == DRAW){
goAcross = -1;
}
if (whichBall == ERASE){
eraseAcross = -1;
}
}
if (areaHIT == BOTTOM){
if (whichBall == DRAW){
goDown = -1;
}
if (whichBall == ERASE){
eraseDown = -1;
}
}
if (areaHIT == LEFT){
if (whichBall == DRAW){
goAcross = 1;
}
if (whichBall == ERASE){
eraseAcross = 1;
}
}
areaHIT = NOTHING;
randColor = 0;
while (areaHIT == NOTHING){
if (across == 5){
areaHIT = LEFT;
whichBall = DRAW;
}
if (across == 1010){
areaHIT = RIGHT;
whichBall = DRAW;
}
if (down == 30){
areaHIT = TOP;
whichBall = DRAW;
}
if (down == 710){
areaHIT = BOTTOM;
whichBall = DRAW;
}
if (secondAcross == 5){
areaHIT = LEFT;
whichBall = ERASE;
}
if (secondAcross == 1010){
areaHIT = RIGHT;
whichBall = ERASE;
}
if (secondDown == 30){
areaHIT = TOP;
whichBall = ERASE;
}
if (secondDown == 710){
areaHIT = BOTTOM;
whichBall = ERASE;
}
across = across + goAcross;
down = down + goDown;
secondAcross = secondAcross + eraseAcross;
secondDown = secondDown + eraseDown;
g.setColor(currentColor);
g.fillOval(across, down, 5, 5);
g.setColor(Color.black);
g.fillOval(secondAcross, secondDown, 5, 5);
delay(10);
}
}
}
public void delay(int p) {
try {
Thread.sleep(p);
}
catch (InterruptedException e) {
}
}
public static void main(String[] args) {
L7_ScreenSaver2 prog = new L7_ScreenSaver2 ();
prog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}