JPanel (Container)
*관계 : 최상위 컨테이너 - 컨테이너 - 컴포넌트
- JPanel 을 상속 받음
- 기본생성자에서 JPanel 설정
ㄴ setBounds(int x,y,w,h)
ㄴ setBackground(Color c) - JFrame에 붙여서 사용
ㄴ add(JPanel p)
package GUI;
import java.awt.*;
import javax.swing.*;
class MyPanel extends JPanel{
public MyPanel() {
setBounds(0, 0, 200, 200);
setBackground(Color.orange); // java.awt.Color
}
}
public class MyFrame extends JFrame {
public MyFrame() {
super("JFrame");
setBounds(100,100,800,600);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
add(new MyPanel()); // JFrame에 JPanel 추가
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
}
}
'GUI' 카테고리의 다른 글
[4] Component | Jbutton (0) | 2021.01.12 |
---|---|
[3] Container와 Component (0) | 2021.01.12 |
[1] JFrame | Top-level Container (0) | 2021.01.07 |
[0] 준비 (0) | 2021.01.07 |
GUI (0) | 2021.01.07 |
댓글