-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackgroundAnimation.java
63 lines (57 loc) · 1.75 KB
/
BackgroundAnimation.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
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SlideShow extends JFrame {
private static final long serialVersionUID = 1L;
JLabel pic;
Timer tm;
int x = 0;
//Images Path In Array
String[] list = {
"<path 1>",
"<path 2>",
"<path 3>",
"<path 4>",
"<path 5>",
"<path 6>",
"<path 7>"
};
public SlideShow(){
super("Java SlideShow");
pic = new JLabel();
pic.setBounds(40, 30, 700, 300);
//Call The Function SetImageSize
SetImageSize(6);
//set a timer
tm = new Timer(2000,new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SetImageSize(x);
x += 1;
if(x >= list.length )
x = 0;
}
});
add(pic);
tm.start();
setLayout(null);
setSize(800, 400);
getContentPane().setBackground(Color.decode("#bdb67b"));
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
//create a function to resize the image
public void SetImageSize(int i){
ImageIcon icon = new ImageIcon(list[i]);
Image img = icon.getImage();
Image newImg = img.getScaledInstance(pic.getWidth(), pic.getHeight(), Image.SCALE_SMOOTH);
ImageIcon newImc = new ImageIcon(newImg);
pic.setIcon(newImc);
}
public static void main(String[] args){
new SlideShow();
}
}