/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
Container c= getContentPane();
c.setLayout(null);
setTitle("Random Labels");
setBackground(Color.BLUE);
for(int i=0;i<20;i++) {
JLabel Label= new JLabel(Integer.toString(i));
int x= (int)(Math.random()*200)+50;
int y= (int)(Math.random()*200)+50;
c.add(Label);
Label.setBackground(Color.blue);
Label.setLocation(x,y);
Label.setSize(10,10);
Label.setOpaque(true);
}
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/* ****************************이거 나중에 또 해야 됨******************************************
import javax.swing.*;
import java.awt.*;
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);
p2.setBackground(Color.WHITE);
p3.setBackground(Color.YELLOW);
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout(4,4));
p3.setLayout(new FlowLayout());
p1.add(new JLabel("수식입력"));
p1.add(new JTextField(10));
p3.add(new JLabel("계산 결과"));
p3.add(new JTextField(10));
JButton b;
for(int i=0;i<10;i++)
{
b = new JButton(Integer.toString(i));
p2.add(b);
}
b = new JButton("CE"); p2.add(b);
b = new JButton("계산"); p2.add(b);
b = new JButton("+"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("-"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("x"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("/"); p2.add(b); b.setBackground(Color.CYAN);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
Container c= getContentPane();
c.setLayout(new BorderLayout());
setTitle("여러 개의 패널을 가진 프레임");
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);
p2.setBackground(Color.WHITE);
p3.setBackground(Color.YELLOW);
p1.setLayout(new FlowLayout());
p2.setLayout(null);
p3.setLayout(new FlowLayout());
JButton open= new JButton("열기");
JButton close= new JButton("닫기");
JButton leave= new JButton("나가기");
p1.add(open);
p1.add(close);
p1.add(leave);
for(int i=0;i<20;i++) {
JLabel Label= new JLabel("*");
int x= (int)(Math.random()*200)+50;
int y= (int)(Math.random()*200)+50;
p2.add(Label);
Label.setForeground(Color.RED);
Label.setLocation(x,y);
Label.setSize(10,10);
}
JButton inputWordb= new JButton("World Input");
JTextField inputWord= new JTextField(10);
p3.add(inputWordb);
p3.add(inputWord);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}