mojo's Blog
명품 JAVA Programming 제 10장 실습문제 5번 본문
컴포넌트에 폰트를 설정하는 방법 익히기 (폰트 크기 변경)
import javax.swing.*; // JFrame
import java.awt.*; // Container
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.*;
public class MyFrame extends JFrame {
private JLabel la;
public MyFrame() {
setTitle("Open Challenge 10");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
la = new JLabel("Love Java");
la.setFont(new Font("Arial",Font.PLAIN,10));
c.add(la);
c.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
char keyChar=e.getKeyChar();
if(keyChar=='+') {
Font f=la.getFont();
int size = f.getSize();
la.setFont(new Font("Arial",Font.PLAIN,size+5));
}
else if(keyChar=='-') {
Font f=la.getFont();
int size = f.getSize();
la.setFont(new Font("Arial",Font.PLAIN,size-5));
}
}
});
setSize(300, 150); // 프레임 크기 300x300
setVisible(true); // 프레임 출력
c.setFocusable(true);
c.requestFocus();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyFrame();
}
}
'Java' 카테고리의 다른 글
JTextField, JTextArea (0) | 2021.07.29 |
---|---|
JCheckBox / JRadioButton 연습하기 (0) | 2021.07.28 |
명품 JAVA Programming 제 10장 Open Challenge (0) | 2021.07.28 |
KeyListener / MouseListener (0) | 2021.07.28 |
Adapter Class (0) | 2021.07.28 |
Comments