-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.java
99 lines (90 loc) · 2.92 KB
/
test.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
package mao;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@SuppressWarnings("serial")
public class test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
test frame = new test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public test() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screenSize.getWidth();
int height = (int)screenSize.getHeight();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, width-1, height-1);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton button = new JButton("");
button.setIcon(new ImageIcon("images/run.gif"));
button.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_A) {
button.setIcon(new ImageIcon("images/run.gif"));
button.setBounds(button.getX()-20, button.getY(), button.getWidth(), button.getHeight());
}
if (e.getKeyCode() == KeyEvent.VK_B) {
dispose();
}
if (e.getKeyCode() == KeyEvent.VK_D){
button.setIcon(new ImageIcon("images/runright.gif"));
button.setBounds(button.getX()+20, button.getY(), button.getWidth(), button.getHeight());
}
if (e.getKeyCode() == KeyEvent.VK_W) {
button.setBounds(button.getX(), button.getY()-20, button.getWidth(), button.getHeight());
}
if (e.getKeyCode() == KeyEvent.VK_S){
button.setBounds(button.getX(), button.getY()+20, button.getWidth(), button.getHeight());
}
if (e.getKeyCode() == KeyEvent.VK_C)
{
}
if(e.getKeyCode() == KeyEvent.VK_Z)
{
button.setIcon(new ImageIcon("images/attack.gif"));
}
}
});
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
dispose();
}
});
button.setBounds(330, 255, 145, 209);
contentPane.add(button);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);
setVisible(true);
}
}