-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFishing.java
More file actions
107 lines (90 loc) · 3.11 KB
/
Fishing.java
File metadata and controls
107 lines (90 loc) · 3.11 KB
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
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Timer;
import java.util.TimerTask;
public class Fishing{
char key;
String[] fishArray = {"Salmon", "Flatfish", "Squid", "Octopus", "Minnow", "Shrimp", "Carp", "Tuna", "Mackerel", "Saury"};
JFrame fishing, Message;
JLabel text,letter;
MyLabel bar;
JButton button, button2;
Sound s;
User user;
public Fishing (User user, MyLabel bar, char key, Sound s){
fishing = new JFrame();
Message= new JFrame();
fishing.setTitle("bar");
fishing.setLayout(new GridLayout(3,1));
button = new JButton("Return to home");
text = new JLabel("<html> Press "+key+" to wind your fishing rod</html>");
this.bar = bar;
this.s=s;
this.user=user;
this.key=key;
}
public void play(){
text.setFont(text.getFont().deriveFont(30.0f));
text.setVerticalAlignment(SwingConstants.BOTTOM);
text.setHorizontalAlignment(SwingConstants.CENTER);
fishing.add(text);
Timer timer = new Timer();
TimerTask task = new TimerTask(){
public void run(){
s.stopBgm();
s.playSound(new File("music/fail.wav"), 1.0f, false);
fishing.dispose();
Message.pack();
Message.setLocation(100,100);
Message.setSize(800,500);
letter = new JLabel("fail:(");
letter.setFont(letter.getFont().deriveFont(25.0f));
letter.setVerticalAlignment(SwingConstants.CENTER);
letter.setHorizontalAlignment(SwingConstants.CENTER);
button2 = new JButton("Return to home");
Message.add(letter,BorderLayout.CENTER);
Message.add(button2,BorderLayout.SOUTH);
Message.setVisible(true);
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Message.dispose();
}
});
}
};
timer.schedule(task, 7000);
bar.setBackground(new Color(212,244,250));
bar.setOpaque(true);
bar.setLocation(20, 50);
bar.setSize(300,20);
fishing.add(bar);
fishing.add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
fishing.dispose();
}
});
fishing.setVisible(true);
fishing.addKeyListener(new KeyListener(){
@Override
public void keyTyped(KeyEvent ke) {
}
@Override
public void keyPressed(KeyEvent ke) {
if(ke.getKeyChar() == key)
bar.fill(user, timer);
}
@Override
public void keyReleased(KeyEvent ke) {
}
});
fishing.setLocation(100,100);
fishing.setSize(800,500);
fishing.setVisible(true);
fishing.requestFocus();
ConsumerThread th = new ConsumerThread(bar);
th.start();
}
}