/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
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);
}
public static void main(String[] args) {
new Main();
}
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
if(b.getText().equals("Action"))
b.setText("액션");
else
b.setText("Action");
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
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().contentEquals("Action"))
b.setText("액션");
else
b.setText("Action");
Main.this.setTitle(b.getText());
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
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");
c.add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
if(b.getText().equals("Action"))
b.setText("액션");
else
b.setText("Action");
setTitle(b.getText());
}
});
setSize(350, 150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JLabel la = new JLabel("Hello");
public Main() {
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(true);
}
class MyMouseListener implements MouseListener{
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
la.setLocation(x,y);
}
public void mouseReleased(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JLabel la = new JLabel("Hello");
public Main() {
setTitle("Mouse 이벤트 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.addMouseListener(new MyMouseAdapter());
c.setLayout(null);
la.setSize(50,50);
la.setLocation(30,30);
c.add(la);
setSize(250,250);
setVisible(true);
}
class MyMouseAdapter extends MouseAdapter{
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
la.setLocation(x,y);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JLabel [] keyMessage;
public Main() {
setTitle("keyMessage 예제");
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, 150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
char keyChar = e.getKeyChar();
keyMessage[0].setText(Integer.toString(keyCode));
keyMessage[1].setText(Character.toString(keyChar));
keyMessage[2].setText(KeyEvent.getKeyText(keyCode));
System.out.println("KeyPressed");
}
public void keyReleased(KeyEvent e) {
System.out.println("KeyReleased");
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
public JLabel la = new JLabel("Love Java");
public Main() {
setTitle("마우스 올리기 내리기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setFocusable(true);
c.requestFocus();
c.setLayout(new FlowLayout());
c.addMouseListener(new MyMouseAdapter());
c.add(la);
setSize(300, 200);
setVisible(true);
}
class MyMouseAdapter extends MouseAdapter{
public void mouseEntered(MouseEvent e) {
la.setText("사랑해");
}
public void mouseExited(MouseEvent e) {
la.setText("Love Java");
}
}
public static void main(String[] args) {
new Main();
}
}