-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scanner.java
143 lines (71 loc) · 2.57 KB
/
Scanner.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Image Scanner Animation
// Author: Tinsae Belay
import java.awt.image.*;
import java.awt.event.*;
import java.awt.*;
import javax.imageio.*;
import javax.swing.*;
import java.io.*;
public class Scanner extends Component implements ActionListener{
JFrame window;
File theImage;
BufferedImage img;
BufferedImage oldCopy;
int imageWidth;
int imageHeight;
int greenScannerY;
int greenScannerHeight = 100;
boolean greenScannerToUp;
Color dimGreen;
@Override
public void actionPerformed(ActionEvent event){
try{
img = ImageIO.read( theImage );
}
catch(Exception ex){
// Exception e
}
if( greenScannerToUp ){ //
greenScannerY-=5;
if(greenScannerY <= 0){
greenScannerToUp = false;
}
}
else{
greenScannerY+=5;
if(greenScannerY + greenScannerHeight >= imageHeight){
greenScannerToUp = true;
}
}
Graphics2D g = (Graphics2D) this.getGraphics();
Graphics2D imageG = (Graphics2D) img.getGraphics();
imageG.setColor(dimGreen);
imageG.fillRect( 0,greenScannerY, imageWidth,greenScannerHeight );
imageG.setColor( new Color(255,0,0,200) );
imageG.setFont( new Font("lucida console",Font.PLAIN,60) );
imageG.drawString( "scanning image",50,greenScannerY+40 );
g.drawImage( img, 0,0,imageWidth,imageHeight ,0,0,imageWidth,imageHeight, null);
}
public Scanner(){
theImage = new File( JOptionPane.showInputDialog(null,"File name") );
try{
img = ImageIO.read( theImage );
imageWidth = img.getWidth();
imageHeight = img.getHeight();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"File not found!");
}
dimGreen = new Color(0,255,0,100);
window = new JFrame("Image Scanner Animation");
window.add( this );
window.setSize(imageWidth,imageHeight);
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
window.setVisible(true);
}
public static void main(String[] str){
Scanner sc = new Scanner();
Timer t = new Timer( 100,sc );
t.start();
}
}