*/
//9.GUI/실습/01
/*
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
public Main(){
setTitle("Let's study Java");
setSize(400, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/02
/*
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame{
public Main() {
setTitle("BorderLayout Particle");
setSize(400,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout(5, 7));
cnt.add(new JButton("Center"), BorderLayout.CENTER);
cnt.add(new JButton("West"), BorderLayout.WEST);
cnt.add(new JButton("East"), BorderLayout.EAST);
cnt.add(new JButton("North"), BorderLayout.NORTH);
cnt.add(new JButton("South"), BorderLayout.SOUTH);
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/03
/*
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
public Main() {
setTitle("Ten Color Buttons Frame");
setSize(550,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new GridLayout());
for(int i = 0; i <= 9; i++) {
cnt.add(new JButton(Integer.toString(i)));
}
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/04
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame {
Color c[] = {Color.red, Color.orange, Color.yellow, Color.green, Color.cyan, Color.blue, Color.magenta, Color.darkGray, Color.pink, Color.gray};
public Main() {
setTitle("Ten color Buttons Frame");
setSize(550, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new GridLayout());
for(int i = 0; i <= 9; i++) {
JButton b = new JButton(Integer.toString(i));
b.setBackground(c[i]);
cnt.add(b);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/05
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame {
Color clr[] = {Color.red, Color.orange, Color.yellow, Color.green,
Color.cyan, Color.blue, Color.magenta, Color.gray,
Color.pink, Color.gray, Color.white, Color.darkGray,
Color.black, Color.orange,Color.blue,Color.magenta};
public Main() {
setTitle("4x4 Color Frame");
setSize(550, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new GridLayout(4,4,0,0));
for(int i = 0; i <= 15; i++) {
JLabel lbl = new JLabel(Integer.toString(i));
lbl.setBackground(clr[i]);
lbl.setOpaque(true);
cnt.add(lbl);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/06
/*
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
public Main() {
setTitle("Random Labels");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
for(int i = 0; i < 20; i++) {
int x = (int)(Math.random()*200) + 50;
int y = (int)(Math.random()*200) + 50;
JLabel label = new JLabel(Integer.toString(i));
label.setLocation(x, y);
label.setSize(10, 10);
label.setOpaque(true);
label.setBackground(Color.blue);
add(label);
}
setSize(300, 300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
//9.GUI/실습/07
import java.awt.*;
import javax.swing.*;
class Main extends JFrame {
String text[] = {"0", "1", "2", "3",
"4", "5", "6", "7",
"8", "9", "CE", "계산",
"+", "-", "x", "/"};
public Main() {
setTitle("계산기 프레임");
setSize(300,250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
JPanel pnl1 = new JPanel();
pnl1.setBackground(Color.gray);
pnl1.setLayout(new FlowLayout());
pnl1.add(new JLabel(" 수식입력"));
pnl1.add(new JTextField(" "));
JPanel pnl2 = new JPanel();
pnl2.setBackground(Color.white);
pnl2.setLayout(new GridLayout(4,4,5,5));
for(int i = 0; i < 16; i++) {
JButton btn = new JButton(text[i]);
if(i > 11) {
btn.setBackground(Color.cyan);
}
pnl2.add(btn);
}
JPanel pnl3 = new JPanel();
pnl3.setBackground(Color.yellow);
pnl3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
pnl3.add(new JLabel(" 계산 결과"));
pnl3.add(new JTextField(" "));
cnt.add(pnl1, BorderLayout.NORTH);
cnt.add(pnl2, BorderLayout.CENTER);
cnt.add(pnl3, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
//9.GUI/실습/08
/*
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class Main extends JFrame {
String word1[] = {"열기", "닫기", "나가기"};
JPanel pnl2 = new JPanel();
public Main() {
setTitle("여러 개의 패널을 가진 프레임");
setSize(300, 250);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
JPanel pnl1 = new JPanel();
pnl1.setBackground(Color.gray);
pnl1.setLayout(new FlowLayout());
for(int i = 0; i < 3; i++) {
pnl1.add(new JButton(word1[i]));
}
JButton button1 = new JButton("mouseEvent");
pnl1.add(button1);
button1.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
pnl1.removeAll();
pnl1.repaint();
}
@Override
public void mouseExited(MouseEvent e) {
button1.setBackground(Color.gray);
}
@Override
public void mouseEntered(MouseEvent e) {
button1.setBackground(Color.red);
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
});
pnl2.setBackground(Color.white);
pnl2.setLayout(null);
for(int i = 0; i < 10; i++) {
JLabel lbl = new JLabel("*");
int x = (int)(Math.random()*250);
int y = (int)(Math.random()*100)+30;
lbl.setLocation(x, y);
lbl.setSize(10,10);
lbl.setForeground(Color.red);
lbl.setOpaque(true);
pnl2.add(lbl);
}
JPanel pnl3 = new JPanel();
pnl3.setBackground(Color.yellow);
pnl3.setLayout(new FlowLayout(FlowLayout.LEFT,3,0));
JButton button = new JButton("Word Input");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pnl2.removeAll();
pnl2.repaint();
}
});
pnl3.add(button);
JTextField tf = new JTextField(" ");
tf.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JLabel lbl = new JLabel(tf.getText());
int x = (int)(Math.random()*250);
int y = (int)(Math.random()*100)+30;
lbl.setLocation(x, y);
lbl.setSize(50,10);
lbl.setForeground(Color.green);
lbl.setOpaque(true);
pnl2.add(lbl);
pnl2.repaint();
tf.setText("");
}
});
pnl3.add(tf);
cnt.add(pnl1 ,BorderLayout.NORTH);
cnt.add(pnl2 ,BorderLayout.CENTER);
cnt.add(pnl3 ,BorderLayout.SOUTH);
setVisible(true);
}
// class MyActionListener implements ActionListener{
//
// public void actionPerformed(ActionEvent e) {
// JLabel lbl = new JLabel("*");
// int x = (int)(Math.random()*250);
// int y = (int)(Math.random()*100)+30;
// lbl.setLocation(x, y);
// lbl.setSize(10,10);
// lbl.setForeground(Color.red);
// lbl.setOpaque(true);
// pnl2.add(lbl);
//
// //pnl2.revalidate();
// pnl2.repaint();
// }
//
// }
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class NorthPanel extends JPanel{
String[] word1 = {"Open", "Read", "Close"};
public NorthPanel() {
setBackground(Color.darkGray);
setLayout(new FlowLayout(FlowLayout.CENTER,10,0));
for(int i = 0; i < 3; i++) {
add(new JButton(word1[i]));
}
}
}
class CenterPanel extends JPanel {
String[] word2 = {"Hello", "Java", "Love"};
public CenterPanel() {
setBackground(Color.gray);
setLayout(null);
for(int i = 0; i < 3; i++) {
JLabel lbl = new JLabel(word2[i]);
int x = (int)(Math.random()*250);
int y = (int)(Math.random()*250)+30;
lbl.setLocation(x, y);
lbl.setSize(30,30);
lbl.setForeground(Color.black);
lbl.setBackground(Color.gray);
lbl.setOpaque(true);
add(lbl);
}
}
}
class Main extends JFrame {
Main(){
setTitle("Open Challenge 9");
setSize(400, 400);
setLayout(new BorderLayout());
add(new NorthPanel(),BorderLayout.NORTH);
add(new CenterPanel(), BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
import java.awt.*;
import javax.swing.*;
class Main extends JFrame {
public Main() {
setTitle("Action 이벤트 리스너 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(350,150);
Container cnt = getContentPane();
cnt.set
JButton btn = new JButton();
add(btn);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}