/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
class BtnSet {
Color background,foreGroud;
String Text;
int width,height;
public BtnSet(Color back, Color fore, String txt, int wid, int hei) {
this.background = back;
this.foreGroud = fore;
this.Text = txt;
this.width = wid;
this.height = hei;
}
}
public class Main extends JFrame {
Map<String, String> hashMap = new HashMap<String, String>();
JLabel value;
JTextArea log;
JButton[] btns = new JButton[4];
JTextField engField, korField;
BtnSet[] BtnSets = {new BtnSet(Color.yellow, Color.black, "저장", 90, 30),
new BtnSet(Color.green, Color.black, "찾기", 90, 30),
new BtnSet(Color.magenta, Color.black, "삭제", 90, 30),
new BtnSet(Color.cyan, Color.black, "모두보기", 135, 30)};
public Main() {
setTitle("단어 사전 만들기");
setSize(350,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cnt = getContentPane();
cnt.setLayout(new FlowLayout());
cnt.add(new JLabel(" 영어"));
engField = new JTextField(11);
cnt.add(engField);
cnt.add(new JLabel(" 한글"));
korField = new JTextField(11);
cnt.add(korField);
for(int i = 0; i < btns.length; i++) {
btns[i] = new JButton();
btns[i].setBackground(BtnSets[i].background);
btns[i].setForeground(BtnSets[i].foreGroud);
btns[i].setText(BtnSets[i].Text);
btns[i].setSize(BtnSets[i].width, BtnSets[i].height);
cnt.add(btns[i]);
}
value = new JLabel(Integer.toString(hashMap.size()));
cnt.add(value);
log = new JTextArea(7,20);
cnt.add(new JScrollPane(log));
btns[0].addActionListener(new ActionListener() {
@Override//saveBtn
public void actionPerformed(ActionEvent e) {
if(engField.getText().equals("") && korField.getText().equals("")) {
if(engField.getText().equals("")) {
log.append("error.영어 단어 비입력" + "\n");
korField.setText("");
}
if(korField.getText().equals("")) {
log.append("error.한글 단어 비입력" + "\n");
engField.setText("");
}
}
else {
try {
if(hashMap.get(engField.getText()).equals(null)) {
}
}catch(Exception e1) {
hashMap.put(engField.getText(), korField.getText());
value.setText(Integer.toString(hashMap.size()));
log.append("삽입(" + engField.getText() +"," + korField.getText() +")" + "\n");
engField.setText("");
korField.setText("");
return;
}
log.append("error.이미 존재하는 단어" + "\n");
engField.setText("");
korField.setText("");
}
}
});
btns[1].addActionListener(new ActionListener() {
@Override//FindBtn
public void actionPerformed(ActionEvent e) {
if(engField.getText().equals("") && korField.getText().equals("")) {
if(engField.getText().equals("")) {
log.append("error.영어 단어 비입력" + "\n");
korField.setText("");
}
if(korField.getText().equals("")) {
log.append("error.한글 단어 비입력" + "\n");
engField.setText("");
}
}
else {
try {
if(hashMap.get(engField.getText()).equals(null)) {
}
}catch(Exception e1) {
log.append("error.존재하지 않는 단어" + "\n");
engField.setText("");
korField.setText("");
return ;
}
korField.setText(hashMap.get(engField.getText()));
engField.setText("");
}
}
});
btns[2].addActionListener(new ActionListener() {
@Override//DeleteBtn
public void actionPerformed(ActionEvent e) {
if(engField.getText().equals("") && korField.getText().equals("")) {
if(engField.getText().equals("")) {
log.append("error.영어 단어 비입력" + "\n");
korField.setText("");
}
if(korField.getText().equals("")) {
log.append("error.한글 단어 비입력" + "\n");
engField.setText("");
}
}
else {
try {
if(hashMap.get(engField.getText()).equals(null)) {
}
}catch(Exception e1) {
log.append("error.존재하지 않는 단어" + "\n");
engField.setText("");
korField.setText("");
return ;
}
log.append("삭제(" + engField.getText() +"," + hashMap.get(engField.getText()) +")" + "\n");
hashMap.remove(engField.getText());
engField.setText("");
}
}
});
btns[3].addActionListener(new ActionListener() {
@Override//allBtn
public void actionPerformed(ActionEvent e) {
log.setText("");
Iterator<String> keys = hashMap.keySet().iterator();
while(keys.hasNext()) {
String key = keys.next();
String value = hashMap.get(key);
log.append("삭제(" + key +"," + value +")" + "\n");
}
}
});
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("JPanel의 paintComponent()의 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(250,220);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawRect(10, 10, 50, 50);
g.drawRect(50, 50, 50, 50);
g.setColor(Color.magenta);
g.drawRect(90, 90, 50, 50);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("drawString 사용 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(250,200);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("자바는 재밌다.~~", 30, 30);
g.drawString("얼마나? 하늘만큼 땅만큼 !!!!", 60, 60);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("Color, Font 사용 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(350, 470);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawString("I Love Java.~~", 30, 30);
g.setColor(new Color(255,0,0));
g.setFont(new Font("Arial", Font.ITALIC, 30));
g.drawString("How much?", 30, 60);
g.setColor(new Color(0x00ff0ff));
for(int i=1; i<=5; i++) {
g.setFont(new Font("Jokerman", Font.ITALIC, i*10));
g.drawString("This much!!", 30, 60+i*60);
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("drawLine 사용 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(200, 170);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.drawLine(20, 20, 100, 100);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("fillXXX 사용 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(100,350);
setVisible(true);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.fillRect(10, 10, 50, 50);
g.setColor(Color.BLUE);
g.fillOval(10, 70, 50, 50);
g.setColor(Color.GREEN);
g.fillRoundRect(10, 130, 50, 50, 20, 20);
g.setColor(Color.MAGENTA);
g.fillArc(10, 190, 50, 50, 0, 270);
g.setColor(Color.ORANGE);
int [] x = {30,10,30,60};
int [] y = {250,275,300,275};
g.fillPolygon(x, y, 4);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("원본 크기로 원하는 위치에 이미지 그리기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(300,420);
setVisible(true);
}
class MyPanel extends JPanel {
private ImageIcon icon = new ImageIcon("images/image0.jag");
private Image img = icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 20, 20, this);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("패널의 크기에 맞추어 이미지 그리기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(200, 300);
setVisible(true);
}
class MyPanel extends JPanel {
private ImageIcon icon = new ImageIcon("images/image0.jpg");
private Image img = icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("이미지 일부분을 크기 조절하여 그리기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(300,300);
setVisible(true);
}
class MyPanel extends JPanel {
private ImageIcon icon = new ImageIcon("images/image0.jpg");
private Image img = icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 20, 20, 250, 100, 100, 50, 200, 200, this);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("클리핑 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(300,400);
setVisible(true);
}
class MyPanel extends JPanel {
private ImageIcon icon = new ImageIcon("images/image0.jpg");
private Image img = icon.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setClip(100, 20,150, 150);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
g.setColor(Color.YELLOW);
g.setFont(new Font("Arial", Font.ITALIC, 40));
g.drawString("Go Gator!!", 10, 150);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Main extends JFrame {
private MyPanel panel = new MyPanel();
public Main() {
setTitle("drawing Line by Mouse 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(panel);
setSize(300, 300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
class MyPanel extends JPanel {
private Vector<Point> vStart = new Vector<Point>();
private Vector<Point> vEnd = new Vector<Point>();
public MyPanel() {
addMouseMotionListener(new MouseAdapter(){
public void mousePressed(MouseEvent e) {
Point startP = e.getPoint();
vStart.add(startP);
System.out.println("1");
}
public void mouseReleased(MouseEvent e) {
Point endP = e.getPoint();
vEnd.add(endP);
repaint();
}
});
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
for(int i=0; i<vStart.size(); i++) {
Point s = vStart.elementAt(i);
Point e = vEnd.elementAt(i);
g.drawLine((int)s.getX(), (int)s.getY(), (int)e.getX(), (int)e.getY());
}
}
}
}
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("새로운 버튼 만들기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
MyButton b = new MyButton("New Button");
b.setOpaque(true); b.setBackground(Color.CYAN);
c.add(b);
setSize(250,200); setVisible(true);
}
class MyButton extends JButton {
public MyButton(String s) {
super(s);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.drawOval(0, 0, this.getWidth()-1, this.getHeight()-1);
}
}
public static void main(String[] args) {
new Main();
}
}
*/