/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JLabel [] keyMessage;
public Main() {
setTitle("keyListener 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
keyMessage = new JLabel [3];
keyMessage[0] = new JLabel(" getKeyCode");
keyMessage[1] = new JLabel(" getKeyChar");
keyMessage[2] = new JLabel(" getKeyText");
for(int i=0;i<keyMessage.length; i++) {
c.add(keyMessage[i]);
keyMessage[i].setOpaque(true);
keyMessage[i].setBackground(Color.yellow);
}
setSize(300,300);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
keyMessage[0].setText(Integer.toString(e.getKeyCode()));
keyMessage[1].setText(Character.toString(e.getKeyChar()));
keyMessage[2].setText(KeyEvent.getKeyText(e.getKeyCode()));
}
// public void keyReleased(KeyEvent e) {
//
// }
// public void keyTyped(KeyEvent e) {
//
// }
}
public static void main(String[] args) {
new Main();
}
}
int d=10;
int x = la.getX();
la.setLocation(x+d,y);
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Main extends JFrame{
Container c = getContentPane();
public Main() {
c.setFocusable(true);
c.requestFocus();
setSize(300,300);
setVisible(true);
c.setLayout(null);
c.addKeyListener(new MMMbti());
}
class MMMbti extends KeyAdapter{
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_F1)
{
System.out.println(1);
c.setBackground(Color.green);
}
if(e.getKeyCode()==KeyEvent.VK_5) {
System.out.println(2);
c.setBackground(Color.YELLOW);
}
}
}
public static void main(String[] args) {
new Main();
}
}*/
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.awt.event.*;
import java.awt.*;
class Main extends JFrame{
JFileChooser chooser = new JFileChooser();
int flag=0;
MyModalDialog dialog;
DangerMessage dialog1;
public int o = 5;
Container c = getContentPane();
JLabel la = new JLabel("Player");
JButton speed = new JButton("Speed");
public Main() {
dialog = new MyModalDialog(this, "Admin Login");
dialog1 = new DangerMessage();
c.setLayout(null);
la.setSize(100, 100);
la.setLocation(400, 400);
speed.setLocation(10, 10);
speed.setSize(100,50);
c.add(la);
c.add(speed);
c.setFocusable(true);
c.requestFocus();
setSize(1000,1000);
setVisible(true);
speed.addActionListener(new Button());
c.addKeyListener(new MMMbti());
}
class MMMbti extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int x = la.getX();
int y = la.getY();
//System.out.println(e.getKeyCode());
if(e.getKeyChar()=='g')
{
dialog1.setVisible(true);
int ret = chooser.showOpenDialog(null);
if(ret == JFileChooser.APPROVE_OPTION) {
String pathName = chooser.getSelectedFile().getPath();
String fileName = chooser.getSelectedFile().getName();
System.out.println(fileName);
try {
FileReader fin = new FileReader(pathName);
int c= fin.read();
String p= "";
while(c != ' '|| c!= -1) {
p = p + ((char)c);
c = fin.read();
}
la.setText(p);
System.out.println(c);
fin.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("파일을 열 수 없음");
}
catch(IOException e2) {
System.out.println("입출력 오류");
}
}
c.setFocusable(true);
c.requestFocus();
}
if(e.getKeyChar()=='c')
{
dialog.setVisible(true);
}
if(e.getKeyChar()=='v')
{
flag = 0;
o=5;
}
if(e.getKeyCode()==KeyEvent.VK_UP)
{
System.out.println("up");
la.setLocation(x, y-o);
}
if(e.getKeyCode()==KeyEvent.VK_DOWN) {
System.out.println("down");
la.setLocation(x, y+o);
}
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
System.out.println("right");
la.setLocation(x+o, y);
}
if(e.getKeyCode()==KeyEvent.VK_LEFT) {
System.out.println("left");
la.setLocation(x-o, y);
}
if(e.getKeyCode()==KeyEvent.VK_1 && flag == 1) {
o = 10;
}
if(e.getKeyCode()==KeyEvent.VK_2&& flag == 1) {
o = 20;
}
if(e.getKeyCode()==KeyEvent.VK_3&& flag == 1) {
o = 30;
}
if(e.getKeyCode()==KeyEvent.VK_4&& flag == 1) {
o = 40;
}
if(e.getKeyCode()==KeyEvent.VK_5&& flag == 1) {
o = 50;
}
if(e.getKeyCode()==KeyEvent.VK_6&& flag == 1){
System.out.println("Walk");
o = 60;
}
if(e.getKeyCode()==KeyEvent.VK_7&& flag == 1) {
o = 70;
}
if(e.getKeyCode()==KeyEvent.VK_8&& flag == 1) {
o = 80;
}
if(e.getKeyCode()==KeyEvent.VK_9&& flag == 1) {
o = 90;
}
if(e.getKeyCode()==KeyEvent.VK_0&& flag == 1) {
o = 0;
}
}
}
class MyModalDialog extends JDialog{
public JPasswordField tf = new JPasswordField(10);
public JButton OK = new JButton("Enter");
public MyModalDialog(JFrame frame, String title) {
super(frame, title, true);
setLayout(new FlowLayout());
add(tf);
add(OK);
setSize(200,100);
OK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(tf.getText().equals("eovwlkm")) {
flag = 1;
}
else {
flag = 0;
}
setVisible(false);
}
});
}
}
class DangerMessage extends JDialog{
public JPasswordField tf = new JPasswordField(10);
public JButton OK = new JButton("Enter");
public JTextField DangerMessa = new JTextField("텍스트 파일 뒤에' '스페이스바를 꼭 눌러주세요",25);
public JTextField DangerMessa1 = new JTextField("영어만 됍니다",25);
public DangerMessage() {
setLayout(new FlowLayout());
add(DangerMessa);
add(DangerMessa1);
setSize(500,100);
}
}
class Button implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(o == 20) {
o = 5;
}
else {
o = 10;
}
c.setFocusable(true);
c.requestFocus();
}
}
public static void main(String[] args) {
new Main();
}
}