import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
JLabel LL = new JLabel("color");
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(new BorderLayout());
JPanel a=new JPanel();
a.setLayout(new FlowLayout());
JButton b1 = new JButton("yellow");
JButton b2 = new JButton("green");
JButton b3 = new JButton("red");
a.add(b1);
a.add(b2);
a.add(b3);
b1.addActionListener(new MyActionListener1());
b2.addActionListener(new MyActionListener1());
b3.addActionListener(new MyActionListener1());
c.add(a, BorderLayout.NORTH);
JPanel b = new JPanel();
b.setLayout(null);
b.add(LL);
LL.setLocation(100, 100);
LL.setSize(50, 50);
c.add(b, BorderLayout.CENTER);
JTextField tf = new JTextField(15);
a.add(tf);
tf.addActionListener(new MyActionListener2());
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
class MyActionListener2 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
JTextField tf = (JTextField)e.getSource();
String str = tf.getText();
int x=LL.getX();
int y=LL.getY();
if (tf.getText().equals("위"))
LL.setLocation(x, y-10);
else if(tf.getText().equals("아래"))
LL.setLocation(x, y+10);
}
}
class MyActionListener1 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton b=(JButton)e.getSource();
int x = LL.getX();
int y = LL.getY();
if(b.getText().equals("yellow"))
LL.setForeground(Color.yellow);
else if (b.getText().equals("green"))
LL.setForeground(Color.green);
else if(b.getText().equals("red"))
LL.setForeground(Color.red);
else if(b.getText().equals("오른쪽"))
LL.setLocation(x+10, y);
else if(b.getText().equals("왼쪽"))
LL.setLocation(x-10, y);
JButton d=(JButton)e.getSource();
if (d.getText().equals("위"))
LL.setLocation(x, y-10);
else if(d.getText().equals("아래"))
LL.setLocation(x, y+10);
}
}
}*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
private JLabel la=new JLabel("Hello");
public Main(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.addMouseListener((MouseListener) new MyMouseListener());
c.setLayout(null);
la.setSize(250,250);
setVisible(true);
}
class MyMouseListener implements MouseListener{
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
int x=e.getX();
int y=e.getY();
la.setLocation(x, y);
}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public static void main(String[] args) {
new Main();
}
}
}*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
private JLabel la=new JLabel("단어");
public Main(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
la.addMouseListener(new MyMouseListener());
c.setLayout(null);
la.setSize(100,50);
la.setLocation(30,30);
c.add(la);
setSize(250,250);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void mousePressed(MouseEvent e) {
la.setText("push");
}
public void mouseEntered(MouseEvent e) {
la.setText("사랑해");
}
public void mouseExited(MouseEvent e) {
la.setText("Love Java");
}
}
public static void main(String[] args) {
new Main();
}
}*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main implements KeyListener{
private JLabel [] keyMessage;
public Main() {
}
}