/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
Main(){
Container cp=getContentPane();
cp.setLayout(new BorderLayout());
setVisible(true);
setSize(400,400);
JPanel nor=new JPanel();
nor.setSize(400,200);
cp.add(nor,BorderLayout.NORTH);
nor.setBackground(Color.DARK_GRAY);
JPanel cen=new JPanel();
cen.setSize(400,200);
JButton b1=new JButton();
nor.add(b1);
b1.setSize(100,100);
JButton b2=new JButton();
nor.add(b2);
b2.setSize(100,100);
JButton b3=new JButton();
nor.add(b3);
b3.setSize(100,100);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
Main(){
Container cp=getContentPane();
cp.setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setSize(400,400);
JPanel north=new JPanel(new FlowLayout());
JPanel center=new JPanel(new FlowLayout());
cp.add(north,BorderLayout.NORTH);
north.setBackground(Color.DARK_GRAY);
cp.add(center,BorderLayout.CENTER);
JButton b1=new JButton("1");
north.add(b1);
JButton b2=new JButton("2");
north.add(b2);
JButton b3=new JButton("3");
north.add(b3);
b1.setSize(100,200);
JLabel l1=new JLabel("1");
JLabel l2=new JLabel("2");
JLabel l3=new JLabel("3");
center.add(l1);
center.add(l2);
center.add(l3);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame {
Main() {
Container cp = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setSize(300, 300);
cp.setLayout(null);
JLabel[] labels = new JLabel[20];
for (int i = 0; i < labels.length; i++) {
labels[i] = new JLabel(Integer.toBinaryString(i));
int x = (int) (Math.random() * 200 + 50);
int y = (int) (Math.random() * 200 + 50);
labels[i].setLocation(x, y);
labels[i].setSize(15, 15);
labels[i].setOpaque(true);
labels[i].setBackground(Color.blue);
cp.add(labels[i]);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
Main(){
Container cp=getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cp.setLayout(new BorderLayout());
JPanel north = new JPanel();
cp.add(north,BorderLayout.NORTH);
north.setBackground(Color.gray);
JLabel input = new JLabel("수식입력");
north.add(input);
JTextField t1=new JTextField();
t1.setColumns(20);
north.add(t1);
JPanel center = new JPanel();
center.setLayout(new GridLayout(4,4,2,2));
cp.add(center,BorderLayout.CENTER);
JButton[] btns = new JButton[10];
for(int i=0;i<10;i++) {
btns[i]=new JButton(Integer.toString(i));
center.add(btns[i]);
}
JButton CE=new JButton("CE");
center.add(CE);
JButton cal=new JButton("계산");
center.add(cal);
JButton sum=new JButton("+");
center.add(sum);
sum.setBackground(Color.cyan);
JButton m=new JButton("-");
center.add(m);
m.setBackground(Color.cyan);
JButton a=new JButton("x");
center.add(a);
a.setBackground(Color.cyan);
JButton d=new JButton("/");
center.add(d);
d.setBackground(Color.cyan);
JPanel south=new JPanel();
cp.add(south,BorderLayout.SOUTH);
south.setBackground(Color.yellow);
JLabel output = new JLabel("계산결과");
south.add(output);
JTextField t2=new JTextField();
t2.setColumns(20);
south.add(t2);
setVisible(true);
setSize(300,300);
}
public static void main(String[] args) {
new Main();
}
}
리스너 :
액션 (텍스트필드, 버튼)
change (슬라이더..?)
Item (체크박스, 라디오버튼... )
마우스리스너
키리스너
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame {
Container cp = getContentPane();
JPanel north = new JPanel();
JPanel center = new JPanel(null);
JPanel south = new JPanel();
JButton word = new JButton("Word Input");
JTextField input = new JTextField();
Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cp.setLayout(new BorderLayout());
cp.add(center, BorderLayout.CENTER);
north.setLayout(new FlowLayout());
north.setBackground(Color.DARK_GRAY);
cp.add(north, BorderLayout.NORTH);
JButton b1 = new JButton("추가");
JButton b2 = new JButton("초기화");
JButton b3 = new JButton("나가기");
north.add(b1);
b1.addActionListener(new Plus());
north.add(b2);
b2.addActionListener(new Init());
north.add(b3);
b3.addActionListener(new Exit());
// * b3.addActionListener(new ActionListener() { public void
// * actionPerformed(ActionEvent e) { cp.removeAll(); // 컨테이너 내부의 모든 컴포넌트 삭제
// * cp.repaint(); cp.revalidate(); //System.exit(0); } });
// *
// * // b1.addActionListener(new MyActionListener()); // b2.addActionListener(new
// * MyActionListener()); // b3.addActionListener(new MyActionListener());
// *
south.setLayout(new FlowLayout());
south.setBackground(Color.yellow);
cp.add(south, BorderLayout.SOUTH);
input.setColumns(20);
word.addActionListener(new Input());
south.add(word);
south.add(input);
JLabel[] labels = new JLabel[10];
for (int i = 0; i < labels.length; i++) {
labels[i] = new JLabel("*");
int x = (int) (Math.random() * 300) + 50;
int y = (int) (Math.random() * 300) + 50;
labels[i].setLocation(x, y);
labels[i].setSize(10, 10);
center.add(labels[i]);
}
setVisible(true);
setSize(500, 500);
}
class Plus implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
JLabel exlabels = new JLabel("*");
int x = (int) (Math.random() * 300) + 50;
int y = (int) (Math.random() * 300) + 50;
exlabels.setLocation(x, y);
exlabels.setSize(10, 10);
center.add(exlabels);
center.repaint();
center.revalidate();
}
}
class Init implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
center.removeAll(); // 컨테이너 내부의 모든 컴포넌트 삭제
center.repaint();
center.revalidate();
}
}
class Exit implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class Input implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
JLabel exinput = new JLabel(input.getText());
input.setText("");
int x = (int) (Math.random() * 300) + 50;
int y = (int) (Math.random() * 300) + 50;
exinput.setLocation(x, y);
exinput.setSize(30, 30);
center.add(exinput);
center.repaint();
center.revalidate();
}
}
// class MyActionListener implements ActionListener{
// public void actionPerformed(ActionEvent e) {
// JButton bb = (JButton)e.getSource();
// if(bb.getText().equals("나가기"))
// //if(bb==b3)
// bb.setBackground(Color.red);
// //bb.setText("push");
//
// }
// }
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel l=new JLabel("Hello");
Container cp= getContentPane();
Main(){
cp.setLayout(null);
l.setLocation(30,30);
l.setSize(30,30);
cp.add(l);
cp.addMouseListener(new MyMouseListener1());
setVisible(true);
setSize(300,300);
if(==KeyEvent.VK_UP)
}
class MyMouseListener1 extends MouseAdapter{
public void mousePressed(MouseEvent e) {
l.setText("adapter");
}
}
class MyMouseListener implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount()==2)
l.setText("text");
}
@Override
public void mousePressed(MouseEvent e) {
//e객체에는 방금 발생한 이벤트에대한 많은 정보 포함 ( ex) 눌린 곳이 어딘지? 어떤 컴포넌트에서 눌렸는지? 언제 눌렸는지? ..e 왼쪽이눌렸는지?오른쪽이눌렸는지?
e.getk
int x = e.getX();
int y = e.getY();
l.setLocation(x, y);
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mouseExited(MouseEvent e) {
cp.setBackground(Color.DARK_GRAY);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame {
Container cp=getContentPane();
JLabel label=new JLabel("사랑해");
Main(){
cp.setLayout(new FlowLayout());
cp.add(label);
label.addMouseListener(new Mouse());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setSize(300,300);
}
class Mouse implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
label.setText("Love Java");
}
@Override
public void mouseExited(MouseEvent e) {
label.setText("사랑해");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame{
Container cp=getContentPane();
Main(){
cp.setBackground(Color.green);
cp.addMouseMotionListener(new Mouse());
setVisible(true);
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
class Mouse implements MouseMotionListener, MouseListener{
@Override
public void mouseDragged(MouseEvent e) {
cp.setBackground(Color.yellow);
}
@Override
public void mouseMoved(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mouseClicked(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mousePressed(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mouseReleased(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mouseEntered(MouseEvent e) {
cp.setBackground(Color.green);
}
@Override
public void mouseExited(MouseEvent e) {
cp.setBackground(Color.green);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame{
JLabel label=new JLabel("C");
Main(){
Container cp=getContentPane();
cp.setLayout(null);
label.setSize(10,10);
label.setLocation(100,100);
label.addMouseListener(new Mouse());
cp.add(label);
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
class Mouse implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
int x=(int)(Math.random()*200)+50;
int y=(int)(Math.random()*200)+50;
label.setLocation(x,y);
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame{
JLabel lable=new JLabel("Love Java");
Main(){
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(lable);
lable.addMouseWheelListener(new Mouse());
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
class Mouse implements MouseWheelListener{
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
int n=e.getWheelRotation();
Font f = lable.getFont();
int size = f.getSize();
if(n<0) {
lable.setFont(new Font("Arial",Font.PLAIN,size+5));
}
else if(size>=10) {
lable.setFont(new Font("Arial",Font.PLAIN,size-5));
}
System.out.println(lable.getFont().getSize());
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
class Main extends JFrame{
JLabel l1=new JLabel("1");
JLabel l2=new JLabel("2");
JLabel l3=new JLabel("3");
JLabel underl=new JLabel("시작합니다");
Main(){
Container cp=getContentPane();
cp.setLayout(null);
l1.setOpaque(true);
l2.setOpaque(true);
l3.setOpaque(true);
l1.setBackground(Color.green);
l2.setBackground(Color.green);
l3.setBackground(Color.green);
underl.setLocation(160,90);
underl.setSize(100,30);
l1.setSize(70,40);
l1.setLocation(50,30);
l1.setHorizontalAlignment(SwingConstants.CENTER);
l2.setSize(70,40);
l2.setLocation(150,30);
l2.setHorizontalAlignment(SwingConstants.CENTER);
l3.setSize(70,40);
l3.setLocation(250,30);
l3.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(underl);
cp.add(l1);
cp.add(l2);
cp.add(l3);
setSize(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
class key implements KeyListener{
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
new Main();
}
}