}
import java.awt.*;
import javax.swing.*;
import java.util.*;
class Main extends JFrame{
Main(){
setVisible(true);
setSize(700,700);
Container c = getContentPane();
c.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
p1.setBackground(Color.WHITE);
p1.setLayout(null);
c.add(p1,BorderLayout.CENTER);
JPanel p2 = new JPanel();
p2.setBackground(Color.GRAY);
c.add(p2,BorderLayout.NORTH);
JButton b = new JButton("열기");
JButton b1 = new JButton("닫기");
JButton b2 = new JButton("나가기");
p2.add(b);
p2.add(b1);
p2.add(b2);
JPanel p3 = new JPanel();
p3.setBackground(Color.YELLOW);
c.add(p3,BorderLayout.SOUTH);
JButton b3 = new JButton("Word input");
p3.add(b3);
JTextField jt = new JTextField(10);
p3.add(jt);
for(int i=1;i<=10;i++) {
JLabel la = new JLabel("*-*");
p1.add(la);
la.setSize(15, 15);
int x = (int)(Math.random()*200)+50;
int y = (int)(Math.random()*200)+50;
la.setLocation(x, y);
la.setForeground(Color.RED);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
class Main extends JFrame{
Container c = getContentPane();
Main(){
setVisible(true);
setSize(700,700);
c.setLayout(null);
JButton b3 = new JButton("클릭하세요!");
b3.setSize(100, 50);
b3.setLocation(300, 100);
b3.addActionListener(new MyActionListener()); //액션리스너를 붙여줘!
c.add(b3);
}
class MyActionListener implements ActionListener{
int count=0;
public void actionPerformed(ActionEvent e) {
if(count==10) {
c.removeAll();
c.repaint();
}
else
{
count++;
JLabel la = new JLabel("new label!!");
la.setSize(100, 100);
int x = (int)(Math.random()*600)+50;
int y = (int)(Math.random()*600)+50;
la.setLocation(x, y);
c.add(la);
c.repaint(); //다시그리기
}
//e : 이벤트에 대한 정보를 담고있는 객체 ( 이벤트가 어디서 일어났는지?(소스), 일어난 시간?, 일어난 위치)
// JButton b = (JButton)e.getSource();
// if(b.getText().equals("클릭되었음!!"))
// b.setText("클릭 안 됨!");
// else
// b.setText("클릭되었음!!");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
class Main extends JFrame{
//이벤트 리스너랑 같ㅇ이 쓸 컴포넌트는 여기에다가!!
JPanel p1= new JPanel();
Main(){
Container c = getContentPane();
setVisible(true);
setSize(700,700);
c.setLayout(new BorderLayout());
JPanel p = new JPanel();
c.add(p,BorderLayout.NORTH);
JButton b = new JButton("추가 버튼 ");
b.addActionListener(new Action()); //리스너 버튼에 붙여주기
JButton b1 = new JButton("전부 삭제");
p.add(b);
p.add(b1);
c.add(p1,BorderLayout.CENTER);
p1.setLayout(null);
}
class Action implements ActionListener{
public void actionPerformed(ActionEvent e) {
JLabel la = new JLabel("*-*");
la.setSize(100, 100);
int x = (int)(Math.random()*600)+50;
int y = (int)(Math.random()*600)+50;
la.setLocation(x, y);
p1.add(la);
p1.repaint();
}
}
public static void main(String[] args) {
new Main();
}
}



