/*============================================================================= 화살표 키로 글자 움직이기 ==================================================================
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Main extends JFrame{
Container c;
JLabel la=new JLabel("Hello");
public Main(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
c=getContentPane();
c.setLayout(null);
la.setSize(50,20);
la.setLocation(150,150);
c.add(la);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(400,400);
setVisible(true);
}
//implements KeyListener
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e)
{
int X=la.getX();
int Y=la.getY();
switch(e.getKeyCode())
{
case KeyEvent.VK_UP : la.setLocation(X,Y-10); break;
case KeyEvent.VK_DOWN : la.setLocation(X,Y+10); break;
case KeyEvent.VK_RIGHT : la.setLocation(X+10,Y); break;
case KeyEvent.VK_LEFT : la.setLocation(X-10,Y); break;
}
}
}
public static void main(String[] args) {
new Main();
}
}
==============================================================================================================================*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
Container c;
JLabel la=new JLabel("Love Java ");
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
c=getContentPane();
c.setLayout(null);
la.setSize(60,20);
la.setLocation(150,150);
c.add(la);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(300,300);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
public void keyPressed (KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_LEFT) {
if(la.getText().equals("Love Java")) {
la.setText("avaJ evoL");
}
else {
la.setText("Love Java");
}
}
System.out.println("ttt");
}
}
public static void main(String[] args) {
new Main();
}
}*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
Container c;
JLabel la=new JLabel("Love Java");
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
c=getContentPane();
c.setLayout(null);
la.setSize(60,20);
la.setLocation(150,150);
c.add(la);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(300,300);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}}
}