import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
public Main() {
super("JComponent의 공통 메소드 예제");
Container c= getContentPane();
c.setLayout(new FlowLayout());
ImageIcon icon = new ImageIcon("box.png");
ImageIcon icon2 = new ImageIcon("통조림.png");
ImageIcon icon3 = new ImageIcon("coding.png");
//Button
JButton b1=new JButton(icon);
JButton b2=new JButton(" Disabled Button ");
JButton b3=new JButton("geX(), getY()");
b1.setBackground(Color.yellow);
b1.setForeground(Color.MAGENTA);
b1.setFont(new Font("Arial",Font.ITALIC, 20));
b2.setEnabled(false);
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton b=(JButton)e.getSource();
Main frame=(Main)b.getTopLevelAncestor();
frame.setTitle(b.getX()+","+b.getY());
b2.setEnabled(true); //b2를 사용가능하게
}
});
JLabel la=new JLabel(icon2);
JLabel la2=new JLabel(icon3);
c.add(b1); c.add(b2); c.add(b3); c.add(la); c.add(la2);
setSize(680,650);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame{
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon cherryIcon = new ImageIcon("cherry.png");
ImageIcon selectedcherryIcon = new ImageIcon("cherry.png");
JCheckBox apple = new JCheckBox("사과");
JCheckBox pear = new JCheckBox("배", true);
JCheckBox cherry = new JCheckBox("체리", cherryIcon);
cherry.setBorderPainted(true);
cherry.setSelectedIcon(selectedcherryIcon);
c.add(apple);
c.add(pear);
c.add(cherry);
setSize(250,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JCheckBox[]fruits=new JCheckBox[3];
private String [] names= {"사과", "배", "체리"};
private JLabel sumLabel;
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("사과 1개 10원, 배 1개 50원, 체리 1개 20000원"));
MyItemListener listener = new MyItemListener();
for(int i=0;i<fruits.length;i++) {
fruits[i]=new JCheckBox(names[i]);
fruits[i].setBorderPainted(true);
c.add(fruits[i]);
fruits[i].addItemListener(listener);
}
sumLabel=new JLabel("현재 0원 입니다");
c.add(sumLabel);
setSize(250,200);
setVisible(true);
}
class MyItemListener implements ItemListener{
private int sum=0;
@Override
//////////////////////////////////////////////////////
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange()==ItemEvent.SELECTED) {
/////////////////////////////////////////////////////
if(e.getItem()==fruits[0])
sum+=10;
else if (e.getItem()==fruits[1])
sum+=50;
else
sum+=20000;
}
else {
if(e.getItem()==fruits[0])
sum-=10;
else if(e.getItem()==fruits[1])
sum-=50;
else
sum-=20000;
}
sumLabel.setText("현재" + sum + "원 입니다");
}
}
public static void main(String[] args) {
new Main();
}
}*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame{
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(new FlowLayout());
ImageIcon cherryIcon = new ImageIcon("해제 체리.png");
ImageIcon selectedcherryIcon=new ImageIcon("선택 체리.png");
ButtonGroup g=new ButtonGroup();
JRadioButton apple=new JRadioButton("사과");
JRadioButton pear=new JRadioButton("배", true);
JRadioButton cherry=new JRadioButton("체리", cherryIcon);
cherry.setBorderPainted(true);
cherry.setSelectedIcon(selectedcherryIcon);
g.add(apple);
g.add(cherry);
g.add(pear);
c.add(apple);
c.add(pear);
c.add(cherry);
setSize(250,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}*/
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame{
public Main() {
}
}