import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
Main(){
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new BorderLayout(1, 2));
//1. 위 패널
JPanel p_up = new JPanel();
p_up.setBackground(Color.GRAY);
JButton a = new JButton();
JButton a2 = new JButton();
JButton a3 = new JButton();
p_up.add(new JButton("Open"));
p_up.add(new JButton("Read"));
p_up.add(new JButton("Close"));
c.add(p_up, BorderLayout.NORTH);
//2.아래(?) 패널
JPanel p_dw = new JPanel();
p_dw.setBackground(Color.lightGray);
p_dw.setLayout(null);
for(int i=0;i<1;i++) {
String stri = Integer.toString(i); //정수->문자열
p_dw.setSize(50, 50);
int x = (int)(Math.random());
int y = (int) (Math.random());
p_dw.setLocation(x,y);
p_dw.add(new JLabel("Java"));
p_dw.add(new JLabel("Love"));
p_dw.add(new JLabel("Hello"));
c.add(p_dw, BorderLayout.CENTER); }
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
Main(){
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new BorderLayout(1, 2));
//1. 위 패널
JPanel p_up = new JPanel();
p_up.setBackground(Color.GRAY);
JButton a = new JButton(); JButton a2 = new JButton();
JButton a3 = new JButton();
p_up.add(new JButton("열기")); p_up.add(new JButton("닫기"));
p_up.add(new JButton("나가기"));
c.add(p_up, BorderLayout.NORTH);
//2.중앙 패
JPanel p_cen = new JPanel();
p_cen.setLayout(null);
Color[] carray = {Color.red};
for(int i=0;i<10;i++) {
String stri = Integer.toString(i);
JButton b = new JButton(stri);
b.setSize(50, 50);
int x = (int)(Math.random()*800);
int y = (int) (Math.random()*800);
b.setLocation(x,y);
b.setBackground(carray[i]);
c.add(p_cen, BorderLayout.CENTER);
}
//3.아래 패널
JPanel p_dw = new JPanel();
p_dw.setLayout(new GridLayout());
p_dw.setBackground(Color.yellow);
JButton a12 = new JButton();
JTextField a1 = new JTextField();
p_dw.add(new JButton("Word Input"));
p_dw.add(new JTextField());
c.add(p_dw, BorderLayout.SOUTH);
setSize(1000, 1000);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}