ㆍ내렸을 때
ㆍ올렸을 때
.
.
.
.
.
.
.
.
.
.
※ 색 안변함.
.
.
.
.
.
public class MyFrame extends JFrame {
Container contentPane = getContentPane();
MyFrame() {
setTitle("드래깅 색변화 연습");
setDefaultCloseOperation(EXIT_ON_CLOSE);
contentPane.addMouseListener(new MyMouseListener());
contentPane.setBackground(Color.GREEN);
setSize(200, 150);
setVisible(true);
}
class MyMouseListener extends MouseAdapter {
public void mouseDragged(MouseEvent e) {
contentPane.setBackground(Color.YELLOW);
}
}
public static void main(String[] args) {
new MyFrame();
}
}
.
.
.
.
.
public class MyFrame extends JFrame {
Container contentPane = getContentPane();
//JPanel contentPane = new JPanel();
JLabel la = new JLabel("Love Java");
MyFrame() {
setTitle("+, - 키로 폰트 크기 변경");
setDefaultCloseOperation(EXIT_ON_CLOSE);
//setContentPane(contentPane);
la.setFont(new Font("Arial", Font.PLAIN, 10));
contentPane.addKeyListener(new MyKeyListener());
contentPane.setLayout(new FlowLayout());
contentPane.add(la);
setSize(500, 450);
setVisible(true);
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
Font f = la.getFont();
int size = f.getSize();
//int keyCode = e.getKeyCode();
/*switch (keyCode) {
case KeyEvent.VK_PLUS: la.setFont(new Font("Arial", Font.PLAIN, size+5)); break;
case KeyEvent.VK_MINUS:
if (size > 9) {
la.setFont(new Font("Arial", Font.PLAIN, size - 5));
}
break;
}
if(e.getKeyChar() == '+') {
la.setFont(new Font("Arial", Font.PLAIN, size+5));
} else if (e.getKeyChar() == '-') {
if (size > 9) {
la.setFont(new Font("Arial", Font.PLAIN, size-5));
}
}
}
}
public static void main(String[] args) {
new MyFrame();
}
}
.
.
.
.
.
✔ 리스너를 적용시킬 대상이 무엇인 지 인지!