xonecas.io
101
Sh

shapesaver / commit dd72e20

uploading old code

xonecas2011-05-11 dd72e20464a3718d4e574a1c25482827f3f4d222

17 files changed

DrawPanel.class+0−0
Binary file, not shown.
DrawPanel.java+123−0
@@ -0,0 +1,123 @@
1+/*
2+ sean caetano martin
3+ seancaetanomartin@gmail.com
4+ CIS 255 HY
5+ DrawPanel.java
6+ assignment#5
7+ 3/28/11
8+*/
9+
10+import java.awt.*;
11+import java.util.Random;
12+import javax.swing.JPanel;
13+import java.awt.event.*;
14+
15+public class DrawPanel extends JPanel implements MouseMotionListener
16+{
17+ //prtivate varibales and random object creation
18+ private Random randomNumbers = new Random();
19+ private int shapeCounter = 0;
20+ private boolean firstTime = true;
21+
22+ public DrawPanel()
23+ {
24+ setBackground (Color.BLACK);
25+ }// end contructor
26+
27+ public void mouseDragged (MouseEvent e){}// end method
28+
29+ public void mouseMoved (MouseEvent e)
30+ {
31+ if (firstTime == true)
32+ {
33+ firstTime = false;
34+ }
35+ else
36+ {
37+ System.exit(0);
38+ }
39+ }// end method
40+
41+ public void paintComponent (Graphics g)
42+ {
43+ // 100 shape reset function
44+ if (shapeCounter == 100)
45+ {
46+ super.paintComponent (g);
47+ shapeCounter = 0;
48+ }
49+
50+ // random color generation
51+ Color color1 = new Color(randomNumbers.nextInt(256),
52+ randomNumbers.nextInt(256),randomNumbers.nextInt(256));
53+ Color color2 = new Color(randomNumbers.nextInt(256),
54+ randomNumbers.nextInt(256),randomNumbers.nextInt(256));
55+
56+ // boolean for gradient value
57+ boolean cyclic = randomNumbers.nextBoolean();
58+ // filled
59+ boolean filled = randomNumbers.nextBoolean();
60+
61+ // position generation for x and y variables
62+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
63+ int width = screenSize.width;
64+ int height = screenSize.height;
65+
66+ int sizeWidth = randomNumbers.nextInt(width);
67+ int sizeHeight = randomNumbers.nextInt(height);
68+
69+ int x1,y1,x2,y2,x3,y3;
70+ x1 = randomNumbers.nextInt(width-sizeWidth);
71+ y1 = randomNumbers.nextInt(height-sizeHeight);
72+ x2 = x1+sizeWidth;
73+ y2 = y1+sizeHeight;
74+ x3 = x1;
75+ y3 = y2;
76+
77+ // boundary control function
78+ if (x2 >= width)
79+ {
80+ x1 = width - sizeWidth;
81+ x2 = width;
82+ }// end if X control
83+ if (y2 >= height)
84+ {
85+ y1 = height - sizeHeight;
86+ y2 = height;
87+ } // end if y control
88+
89+ Shape shape;
90+ //object creation
91+ switch (randomNumbers.nextInt(4))
92+ {
93+ case 1:
94+ shape = new MyOval (x1,y1,x2,y2, color1, filled);
95+ break;
96+ case 2:
97+ shape = new MyRectangle (x1,y1,x2,y2, color1, filled);
98+ break;
99+ case 3:
100+ shape = new MyTriangle (x1,y1,x2,y2,x3,y3, color1);
101+ break;
102+ default:
103+ shape = new MyLine (x1, x2, y1, y2, color1);
104+ break;
105+ }// end switch
106+
107+ // polymorphic draw
108+ Graphics2D g2 = (Graphics2D )g.create();
109+ Paint p = new GradientPaint(0, 0, color1, width/50, height/70, color2, cyclic);
110+ g2.setPaint(p);
111+ shape.draw(g2);
112+ g2.dispose();
113+ shapeCounter++;
114+
115+ try
116+ {
117+ Thread.sleep(700);
118+ }
119+ catch(Exception e) {}
120+
121+ repaint();
122+ }//end method
123+}// end class
MyBoundedShape.class+0−0
Binary file, not shown.
MyBoundedShape.java+65−0
@@ -0,0 +1,65 @@
1+/*
2+ sean caetano martin
3+ seancaetanomartin@gmail.com
4+ CIS 255 HY
5+ MyBoundedShape.java abstract superclass
6+ assignment#5
7+ 3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+
13+public abstract class MyBoundedShape extends Shape
14+{
15+ private boolean filled;
16+
17+ //default contructor
18+ public MyBoundedShape ()
19+ {
20+ super();
21+ }//end default contructor
22+
23+ // constructor
24+ public MyBoundedShape (int x1, int y1, int x2, int y2, Color color, Boolean fill)
25+ {
26+ super (x1,y1,x2,y2,color);
27+ setFilled(fill);
28+ }//end contructor
29+
30+ // getUpperLeftX
31+ public int getUpperLeftX ()
32+ {
33+ return getX1();
34+ }
35+
36+ // getUpperLeftY
37+ public int getUpperLeftY ()
38+ {
39+ return getY1();
40+ }
41+
42+ // getWidth
43+ public int getWidth ()
44+ {
45+ return Math.abs(getX1() - getX2());
46+ }
47+
48+ // getHeight
49+ public int getHeight ()
50+ {
51+ return Math.abs(getY1()- getY2());
52+ }
53+
54+ // isFilled
55+ public boolean isFilled ()
56+ {
57+ return filled;
58+ }
59+
60+ // setfilled
61+ public void setFilled (boolean fill)
62+ {
63+ filled = fill;
64+ }
65+}//end MyBoundedShape
MyLine.class+0−0
Binary file, not shown.
MyLine.java+34−0
@@ -0,0 +1,34 @@
1+/*
2+ sean caetano martin
3+ seancaetanomartin@gmail.com
4+ CIS 255 HY
5+ MyLine.java - line creation object for draw panel
6+ assignment#5
7+ 3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+
13+public class MyLine extends Shape
14+{
15+ // super default constructor call
16+ public MyLine ()
17+ {
18+ super();
19+ }// end super call
20+
21+ // super constructor call
22+ public MyLine (int x1, int y1, int x2, int y2, Color color)
23+ {
24+ super (x1,x2,y1,y2,color);
25+ }// end super call
26+
27+ // draw override
28+ @Override
29+ public void draw (Graphics g)
30+ {
31+ g.setColor(getColor());
32+ g.drawLine(getX1(),getX2(),getY1(),getY2());
33+ }// end draw
34+}// end MyLine
MyOval.class+0−0
Binary file, not shown.
MyOval.java+46−0
@@ -0,0 +1,46 @@
1+/*
2+sean caetano martin
3+seancaetanomartin@gmail.com
4+CIS 255 HY
5+MyOval.java - oval shape creation for draw panel class
6+assignment#5
7+3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+import java.util.Random;
13+
14+public class MyOval extends MyBoundedShape
15+{
16+ // random object for radial draw
17+ private Random randomNumbers = new Random();
18+
19+ // super default constructor call
20+ public MyOval ()
21+ {
22+ super ();
23+ }// end super call
24+
25+ // super constructor call
26+ public MyOval (int x1, int y1, int x2, int y2, Color color, Boolean filled)
27+ {
28+ super (x1,x2,y1,y2,color, filled);
29+ }// end super call
30+
31+ // draw override
32+ @Override
33+ public void draw (Graphics g)
34+ {
35+ g.setColor(getColor());
36+
37+ if (isFilled())
38+ {
39+ g.fillOval(getUpperLeftX(), getUpperLeftY(), getWidth(),getHeight());
40+ }// end if
41+ else
42+ {
43+ g.drawOval(getUpperLeftX(), getUpperLeftY(), getWidth(),getHeight());
44+ }// end else
45+ }// end draw
46+}// end MyOval
MyRectangle.class+0−0
Binary file, not shown.
MyRectangle.java+46−0
@@ -0,0 +1,46 @@
1+/*
2+sean caetano martin
3+seancaetanomartin@gmail.com
4+CIS 255 HY
5+MyRectangle.java - rectangle shape creation for draw panel
6+assignment#5
7+3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+import java.util.Random;
13+
14+public class MyRectangle extends MyBoundedShape
15+{
16+ // random object for radial draw
17+ private Random randomNumbers = new Random();
18+
19+ // super default constructor call
20+ public MyRectangle ()
21+ {
22+ super();
23+ }
24+
25+ // super constructor call
26+ public MyRectangle (int x1, int y1, int x2, int y2, Color color, Boolean filled)
27+ {
28+ super(x1,x2,y1,y2,color,filled);
29+ }
30+
31+ //draw override
32+ @Override
33+ public void draw (Graphics g)
34+ {
35+ g.setColor(getColor());
36+
37+ if (isFilled())
38+ {
39+ g.fillRect(getUpperLeftX(), getUpperLeftY(), getWidth(), getHeight());
40+ }
41+ else
42+ {
43+ g.drawRect(getUpperLeftX(), getUpperLeftY(), getWidth(),getHeight());
44+ }// end else
45+ }// end draw
46+}// and MyRectangle
MyTriangle.class+0−0
Binary file, not shown.
MyTriangle.java+63−0
@@ -0,0 +1,63 @@
1+/*
2+sean caetano martin
3+seancaetanomartin@gmail.com
4+CIS 255 HY
5+MyTriangle.java
6+assignment#5
7+3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+import java.awt.Polygon;
13+import java.util.Random;
14+
15+public class MyTriangle extends MyLine
16+{
17+ private Random randomNumbers = new Random();
18+
19+ Color color;
20+ private int x3;
21+ private int y3;
22+
23+ public MyTriangle ()
24+ {super ();}
25+
26+ public MyTriangle (int x1, int y1, int x2, int y2, int x3, int y3, Color color)
27+ {
28+ super( x1, y1, x2, y2, color );
29+ setX3(x3);
30+ setY3(y3);
31+ }
32+
33+ public void setX3( int thirdX )
34+ {
35+ x3 = ( thirdX < 0 ? 0 : thirdX-thirdX%50 );
36+ }
37+
38+ public int getX3()
39+ {
40+ return x3;
41+ }
42+
43+ public void setY3( int thirdY )
44+ {
45+ y3 = ( thirdY < 0 ? 0 : thirdY-thirdY%50 );
46+ }
47+
48+ public int getY3()
49+ {
50+ return y3;
51+ }
52+
53+ @Override
54+ public void draw (Graphics g)
55+ {
56+ g.setColor(getColor());
57+
58+ int[] xValues = { getX1(), getX2(), getX3() };
59+ int[] yValues = { getY1(), getY2(), getY3() };
60+ g.fillPolygon(xValues,yValues, yValues.length );
61+
62+ }
63+}
README.md+1−0
@@ -0,0 +1 @@
1+A simple screen saver written in Java
ScreenSaver.class+0−0
Binary file, not shown.
ScreenSaver.java+30−0
@@ -0,0 +1,30 @@
1+/*
2+sean caetano martin
3+seancaetanomartin@gmail.com
4+CIS 255 HY
5+ScreenSaver.java
6+assignment#5
7+3/28/11
8+*/
9+
10+import javax.swing.*;
11+import java.awt.*;
12+
13+public class ScreenSaver
14+{
15+ public static void main (String []args)
16+ {
17+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
18+ int width = screenSize.width;
19+ int height = screenSize.height;
20+ DrawPanel panel = new DrawPanel();
21+ JFrame application = new JFrame();
22+ application.setBackground (Color.BLACK);
23+ application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
24+ application.setUndecorated (true);
25+ application.setSize (width,height);
26+ application.add(panel);
27+ application.addMouseMotionListener(panel);
28+ application.setVisible(true);
29+ }
30+}
Shape.class+0−0
Binary file, not shown.
Shape.java+89−0
@@ -0,0 +1,89 @@
1+/*
2+sean caetano martin
3+seancaetanomartin@gmail.com
4+CIS 255 HY
5+Shape.java - abstract superclass
6+assignment#5
7+3/28/11
8+*/
9+
10+import java.awt.Color;
11+import java.awt.Graphics;
12+
13+public abstract class Shape
14+{
15+ // instance variables
16+ private int x1;
17+ private int x2;
18+ private int y1;
19+ private int y2;
20+ private Color myColor;
21+
22+ //default contructor
23+ public Shape ()
24+ {
25+ this.x1 = 0;
26+ this.y1 = 0;
27+ this.x2 = 0;
28+ this.y2 = 0;
29+ myColor = Color.BLACK;
30+ }// end default contructor
31+
32+ // contructor
33+ public Shape (int x1, int x2, int y1, int y2, Color color)
34+ {
35+ setX1(x1);
36+ setX2(x2);
37+ setY1(y1);
38+ setY2(y2);
39+
40+ }// end contructor
41+
42+ // get x1
43+ public int getX1 ()
44+ {return x1;}
45+
46+ // get x2
47+ public int getX2 ()
48+ {return x2;}
49+
50+ // get y1
51+ public int getY1 ()
52+ {return y1;}
53+
54+ // get y2
55+ public int getY2 ()
56+ {return y2;}
57+
58+ // get color
59+ public Color getColor()
60+ {return myColor;}
61+
62+ public void setX1 (int x1)
63+ {
64+ if (x1>=1){this.x1 = x1;}
65+ else{this.x1 = 0;}
66+ }//end set x1
67+
68+ public void setX2 (int x2)
69+ {
70+ if (x2>=1){this.x2 = x2;}
71+ else{this.x2 = 0;}
72+ }//end set x2
73+
74+ public void setY1 (int y1)
75+ {
76+ if (y1>=1){this.y1 = y1;}
77+ else{this.y1 = 0;}
78+ }//end set y1
79+
80+ public void setY2 (int y2)
81+ {
82+ if (y2>=1){this.y2 = y2;}
83+ else{this.y2 = 0;}
84+ }//end set y2
85+
86+ // draw ensure abstract
87+ public abstract void draw (Graphics g);
88+
89+}//end shape