-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBox.java
More file actions
48 lines (45 loc) · 1.27 KB
/
Copy pathTextBox.java
File metadata and controls
48 lines (45 loc) · 1.27 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
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Updates GUI on Pokemon catches
*
* @Jonathan Ke
* @8/27/2019
*/
public class TextBox extends JLabel implements ActionListener
{
private static final long serialVersionUID = 1L;
private String text;
private int index = 0;
Player p;
public TextBox(){
super("Use the arrow keys to move. Press the spacebar to throw pokeballs.");
setBackground(Color.BLACK);
setIcon(new ImageIcon(SpriteSheetCutter.getImage("textbox")));
//font control and text control
Font f = new Font("Joystix",Font.BOLD,12);
setFont(f);
setForeground(Color.WHITE);
setHorizontalTextPosition(SwingConstants.CENTER);
}
public void setText(String txtString){
text = txtString;
index = 0;
Timer t = new Timer(50,this);
t.start();
}
@Override
public void actionPerformed(ActionEvent e){
super.setText(text.substring(0,index));
if (index == text.length()){
((Timer)e.getSource()).stop();
}
index++;
}
}