//import java.awt.*;
//import javax.swing.*;
//
//class Main extends JFrame{
// public Main() {
// setTitle("여러 개의 패널을 가진 프레임");
// Container c = getContentPane();
// c.setLayout(new BorderLayout());
//
// JPanel p1 = new JPanel();
// JPanel p2 = new JPanel();
// JPanel p3 = new JPanel();
//
// c.add(p1, BorderLayout.NORTH);
// c.add(p2, BorderLayout.CENTER);
// c.add(p3, BorderLayout.SOUTH);
//
// p1.setBackground(Color.GRAY);
// p1.setLayout(new FlowLayout());
// p2.setBackground(Color.WHITE);
// p2.setLayout(null);
// p3.setBackground(Color.YELLOW);
// p3.setLayout(new FlowLayout ());
//
// p1.add(new JButton("열기"));
// p1.add(new JButton("닫기"));
// p1.add(new JButton("나가기"));
// p3.add(new JButton("Word Input"));
// p3.add(new JTextField(11));
//
// for(int i=1;i<=10;i++) {
// int x =(int)(Math.random()*400);
// int y =(int)(Math.random()*400);
// JLabel la = new JLabel("*");
// la.setLocation(x,y);
// la.setSize(10,10);
// la.setForeground(Color.RED);
// p2.add(la);
// System.out.println(x+" "+y);
// }
//
// setSize(400,400);
// setVisible(true);
// }
// public static void main(String[] args) {
// new Main();
// }
//}
// 이벤트 리스너 : 컴포넌트에 붙여서, 그 컴포넌트에서 이벤트(클릭등등)이 발생하면 어떤 일을 처리할지 적어놓은 것
//import java.awt.*;
//import javax.swing.*;
//import java.awt.event.*;
//
//class Main extends JFrame{
// JPanel p2 = new JPanel();
// JButton b2 = new JButton("전체삭제");
// JTextField tf = new JTextField(11);
// public Main() {
// setTitle("여러 개의 패널을 가진 프레임");
// Container c = getContentPane();
// c.setLayout(new BorderLayout());
//
// JPanel p1 = new JPanel();
//
// JPanel p3 = new JPanel();
//
// c.add(p1, BorderLayout.NORTH);
// c.add(p2, BorderLayout.CENTER);
// c.add(p3, BorderLayout.SOUTH);
//
// p1.setBackground(Color.GRAY);
// p1.setLayout(new FlowLayout());
// p2.setBackground(Color.WHITE);
// p2.setLayout(null);
// p3.setBackground(Color.YELLOW);
// p3.setLayout(new FlowLayout ());
//
// JButton b1 = new JButton("만들기");
// //b1.addActionListener(new MyActiconListener()); // b1에 액션리스너 붙이기
// p1.add(b1);
//
// b2.addActionListener(new MyActiconListener());
// p1.add(b2);
// p1.add(new JButton("나가기"));
// JButton b3 = new JButton("Word Input");
// b3.addActionListener(new MyActiconListener());
// p3.add(b3);
//
//
// p3.add(tf);
//
// for(int i=1;i<=10;i++) {
// int x =(int)(Math.random()*400);
// int y =(int)(Math.random()*400);
// JLabel la = new JLabel("*");
// la.setLocation(x,y);
// la.setSize(100,10);
// la.setForeground(Color.RED);
// p2.add(la);
// //System.out.println(x+" "+y);
// }
//
// setSize(400,400);
// setVisible(true);
// }
//
// class MyActiconListener implements ActionListener
// {
// // 버튼이 눌렸을때
// public void actionPerformed(ActionEvent e) {
//
// JButton btn = (JButton)e.getSource();
// if(btn==b2) {
// int x =(int)(Math.random()*400);
// int y =(int)(Math.random()*200)+100;
// JLabel la = new JLabel(tf.getText());
// la.setLocation(x,y);
// la.setSize(100,10);
// la.setForeground(Color.RED);
// p2.add(la);
// // 컨테이너에 컴포넌트를 추가했을때 꼭 해야하는 것!
// tf.setText("");
// }
// else {
// p2.removeAll();
// }
//
// p2.repaint();
// p2.revalidate();
// }
//
// }
//
// public static void main(String[] args) {
// new Main();
// }
//}
//import java.awt.*;
//import java.awt.event.*;
//import javax.swing.*;
//public class Main extends JFrame {
// public Main() {
// setTitle("Action 이벤트 리스너 예제");
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Container c = getContentPane();
// c.setLayout(new FlowLayout());
// JButton btn = new JButton("Action");
// btn.addActionListener(new MyActionListener());
// c.add(btn);
//
// setSize(350, 150);
// setVisible(true);
// }
// private class MyActionListener implements ActionListener{
// public void actionPerformed(ActionEvent e) {
// JButton b = (JButton)e.getSource();
// if(b.getText().equals("Action")) {
// b.setText("액션");
// b.setBackground(Color.RED);
// }
// else {
// b.setText("Action");
// b.setBackground(Color.BLUE);
// }
//
// Main.this.setTitle(b.getText());
// }
// }
// public static void main(String[] args) {
// new Main();
// }
//}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseListenerEx extends JFrame {
private JLabel la = new JLabel("Hello");
public MouseListennerEx() {
setTitle("Mouse 이벤트 예제");
setDefaultCLoseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.addMouseListener(new MyMouseListener());
c.setLayout(null);
la.setSize(50, 20);
la.setLocation(30, 30);
c.add(la);
setSize(250, 250);
setVisible(ture);
class MyMouseListener implements MouseListener {
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
la.setLocation(x, y);
}
}
public void
}
}