import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
class Word{
String han_word;
String eng_word;
public Word(String s1,String s2){
han_word=s1;
eng_word=s2;
}
}
public class Book{
public static void main(String[] args) {
ArrayList<Word> list=new ArrayList<>();
list.add(new Word("개","dog"));
list.add(new Word("고양이","cat"));
list.add(new Word("소","cow"));
JFrame f=new JFrame();
f.setSize(600,220);
f.setTitle("English Translator");
JPanel[] jp=new JPanel[2];
for(int i=0; i<jp.length;i++) {
jp[i]=new JPanel();
}
JTextArea txthome= new JTextArea(7,25);
JTextArea txthome2= new JTextArea(7,25);
jp[0].add(txthome);
jp[0].add(txthome2);
f.add(jp[0],BorderLayout.NORTH);
JButton bt1=new JButton("번역");
JButton bt2=new JButton("취소");
jp[1].add(bt1);
jp[1].add(bt2);
f.add(jp[1],BorderLayout.CENTER);
class MyListener implements ActionListener{
private Word word;
public void actionPerformed(ActionEvent e) {
if(e.getSource()==bt1) {
String s=txthome.getText();
for(Word word:list) {
if(s.equals(word.eng_word))
txthome2.setText(word.han_word);
}
}
else {
txthome.setText("");
txthome2.setText("");
}
}
}
bt1.addActionListener(new MyListener());
bt2.addActionListener(new MyListener());
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
