-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathJavaPlot2.java
92 lines (79 loc) · 2.09 KB
/
JavaPlot2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//code by CW Coleman
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Wait {
public static void oneSec() {
try {
Thread.currentThread().sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void manySec(long s) {
try {
Thread.currentThread().sleep(s * 1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void millSec(long s) {
try {
Thread.currentThread().sleep(s);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class JavaPlot2 extends JFrame {
public JavaPlot2()
{
super( "java plot" );
setSize(800,600);
setVisible( true );
}
public void paint( Graphics g )
{
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// only change code below this line
int x, y, h, k, t;
int iRed, iGreen, iBlue, aiRed, aiGreen, aiBlue;//integer RGB
double sRed, sGreen, sBlue;// double start RGB
double eRed, eGreen, eBlue;// double end RGB
double aRed, aGreen, aBlue;// ajust RGB
x = 0; y = 0; h = 0; k = 0; t = 0;
iRed = 127;
iGreen = 64;
iBlue = 0;
aiRed = 3; // adjust integer Red
for (t = 0;t <800;t++){
if (iRed > 255) iRed = 0;
if (iRed < 0) iRed = 255;
g.setColor(new Color(iRed,iGreen,iBlue));
g.drawLine(0,0,800-h,600+k);
iRed = iRed + aiRed;
h = h + 1;
k = k + 1;
// call to Wait class
System.out.println("Ctrl+c to stop. t = " + t+" h= "+h+" k ="+k);
//Wait.millSec(125);
// only change code above this line
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}
// execute application
public static void main( String args[] )
{
JavaPlot2 myobject = new JavaPlot2();//change this
// adapter to handle only windowClosing event
myobject.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent event )
{System.exit( 0 );}
} // end anonymous inner class
); // end call to addWindowListener
}
}// end class Painter