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 MyActionListener());
b2.addActionListener(new MyActionListener());
b3.addActionListener(new MyActionListener());
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);
JButton b4=new JButton("오른쪽");
JButton b5=new JButton("왼쪽");
JButton b6=new JButton("위");
JButton b7=new JButton("아래");
a.add(b4);
a.add(b5);
a.add(b6);
a.add(b7);
b4.addActionListener(new MyActionListener());
b5.addActionListener(new MyActionListener());
b6.addActionListener(new MyActionListener());
b7.addActionListener(new MyActionListener());
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
class MyActionListener 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, 100);
else if(b.getText().equals("왼쪽"))
LL.setLocation(x-10, 100);
else if(b.getText().equals("위"))
LL.setLocation(y+10, 100);
else if(b.getText().equals("아애"))
LL.setLocation(y, 100);
}
}
}



