-
Notifications
You must be signed in to change notification settings - Fork 0
/
RevolutionDairy.java
49 lines (45 loc) · 1.49 KB
/
RevolutionDairy.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
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class RevolutionDairy extends JPanel{
public int page = 0;
private String[] RevolutionDiaryName = {"diary1.jpeg","diary2.jpeg","diary3.jpeg","diary4.jpeg","diary5.jpeg"};
private JButton nextPage;
public RevolutionDairy(){
setLayout(null);
setBounds(0,0,1100,600);
nextPage = new JButton(new ImageIcon("Resource/rightarrow.png"));
nextPage.setContentAreaFilled(false);
nextPage.setBorderPainted(false);
nextPage.setBounds(900,500,80,60);
nextPage.addMouseListener(new ClickHandler());
add(nextPage);
}
public void paintComponent(Graphics g){
g.drawImage(getDiary(RevolutionDiaryName[page]),0,0,1000,600,this);
if(page==4){
nextPage.setVisible(false);
}else{
nextPage.setVisible(true);
}
}
public Image getDiary(String photoName){
Image photo = new ImageIcon("Resource/"+photoName).getImage();
return photo;
}
private class ClickHandler extends MouseAdapter{
@Override
public void mouseClicked(MouseEvent e){
if(e.getSource() == nextPage){
if(page < 4){
page = page + 1;
repaint();
}
}
}
}
}