dictionary.GUI.GUI_Main.java Source code

Java tutorial

Introduction

Here is the source code for dictionary.GUI.GUI_Main.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dictionary.GUI;

import dictionary.algorithmOffine.DicADT;
import dictionary.algorithmOffine.Dict;
import dictionary.algorithmOnline.Glosbe;
import dictionary.algorithmOnline.MyBrowser;
import dictionary.voice.Speech;
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.logging.*;
import javax.swing.*;
import org.json.simple.parser.ParseException;

/**
 *
 * @author DUC TOAN
 */
public class GUI_Main extends javax.swing.JFrame {

    boolean onl = false; //Kiem tra xem dang o che do onl hay offline
    Glosbe run = new Glosbe();
    LinkedList<String> recentWord = new LinkedList<>();
    Dict dicVE = new Dict("src/dictionary/data/VietEng.txt");
    Dict dicEV = new Dict("src/dictionary/data/EngViet.txt");
    DicADT dic;
    Speech voice = new Speech();

    /**
     * Creates new form GUI
     *
     * @throws java.io.FileNotFoundException
     */
    public GUI_Main() throws FileNotFoundException, IOException {

        dic = dicEV;
        initComponents();
        //SetIcon cho frame
        ImageIcon icon = new ImageIcon("src/dictionary/images/find.png");
        Image image = icon.getImage();
        this.setIconImage(image);
        fieldWord.requestFocus();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        frameMean = new javax.swing.JFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        fieldMean = new javax.swing.JEditorPane();
        buttonEdit = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        buttonDelete = new javax.swing.JButton();
        buttonExit = new javax.swing.JButton();
        frameEntries = new javax.swing.JFrame();
        jScrollPane3 = new javax.swing.JScrollPane();
        listEntries = new javax.swing.JList();
        frameAdd = new javax.swing.JFrame();
        fieldAddWord = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        fieldAddMean = new javax.swing.JEditorPane();
        buttonAdd2 = new javax.swing.JButton();
        labelWord = new javax.swing.JLabel();
        buttonCloseAdd = new javax.swing.JButton();
        frameSetting = new javax.swing.JFrame();
        panelVoice = new javax.swing.JPanel();
        button1 = new javax.swing.JRadioButton();
        button2 = new javax.swing.JRadioButton();
        buttonCloseSetting = new javax.swing.JButton();
        buttonAboutUs = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        frameCo = new javax.swing.JFrame();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        main = new javax.swing.JPanel();
        comboBoxEV = new javax.swing.JComboBox();
        fieldWord = new javax.swing.JTextField();
        labelDic = new javax.swing.JLabel();
        labelAuthor = new javax.swing.JLabel();
        buttonAdd = new javax.swing.JButton();
        buttonSetting = new javax.swing.JButton();
        traonl = new javax.swing.JButton();
        comboBoxOnl = new javax.swing.JComboBox();
        buttonSpeech = new javax.swing.JButton();
        buttonUndo = new javax.swing.JButton();
        buttonFind = new javax.swing.JButton();

        frameMean.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frameMean.setTitle("Mean");
        frameMean.setLocation(new java.awt.Point(780, 0));
        frameMean.setName("frameMean"); // NOI18N
        frameMean.setUndecorated(true);
        frameMean.setSize(new java.awt.Dimension(500, 400));

        fieldMean.setEditable(false);
        fieldMean.setBackground(new java.awt.Color(204, 255, 204));
        fieldMean.setContentType("text/html"); // NOI18N
        fieldMean.setAutoscrolls(false);
        fieldMean.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                fieldMeanKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(fieldMean);

        buttonEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/edit.png"))); // NOI18N
        buttonEdit.setText("Edit");
        buttonEdit.setBorder(null);
        buttonEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditActionPerformed(evt);
            }
        });

        buttonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/save.png"))); // NOI18N
        buttonSave.setText("Save");
        buttonSave.setBorder(null);
        buttonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSaveActionPerformed(evt);
            }
        });

        buttonDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/delete.png"))); // NOI18N
        buttonDelete.setText("Delete");
        buttonDelete.setBorder(null);
        buttonDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonDeleteActionPerformed(evt);
            }
        });

        buttonExit.setText("Thot");
        buttonExit.setBorder(null);
        buttonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout frameMeanLayout = new javax.swing.GroupLayout(frameMean.getContentPane());
        frameMean.getContentPane().setLayout(frameMeanLayout);
        frameMeanLayout
                .setHorizontalGroup(
                        frameMeanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(
                                        frameMeanLayout.createSequentialGroup().addContainerGap()
                                                .addComponent(buttonEdit, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(27, 27, 27)
                                                .addComponent(buttonDelete, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        36, Short.MAX_VALUE)
                                                .addComponent(buttonSave, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18))
                                .addComponent(jScrollPane1));
        frameMeanLayout.setVerticalGroup(frameMeanLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(frameMeanLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 348,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(frameMeanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(buttonEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        frameEntries.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frameEntries.setTitle("Entries");
        frameEntries.setAlwaysOnTop(true);
        frameEntries.setAutoRequestFocus(false);
        frameEntries.setLocation(new java.awt.Point(320, 300));
        frameEntries.setName("frameEntries"); // NOI18N
        frameEntries.setUndecorated(true);
        frameEntries.setResizable(false);
        frameEntries.setSize(new java.awt.Dimension(180, 220));

        listEntries.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        listEntries.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listEntries.setAutoscrolls(false);
        listEntries.setVerifyInputWhenFocusTarget(false);
        listEntries.setVisibleRowCount(6);
        listEntries.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listEntriesMouseClicked(evt);
            }
        });
        listEntries.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                listEntriesKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(listEntries);

        javax.swing.GroupLayout frameEntriesLayout = new javax.swing.GroupLayout(frameEntries.getContentPane());
        frameEntries.getContentPane().setLayout(frameEntriesLayout);
        frameEntriesLayout.setHorizontalGroup(
                frameEntriesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                        jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE));
        frameEntriesLayout
                .setVerticalGroup(frameEntriesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE));

        frameAdd.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frameAdd.setTitle("Add Word");
        frameAdd.setLocation(new java.awt.Point(300, 100));
        frameAdd.setUndecorated(true);
        frameAdd.setSize(new java.awt.Dimension(451, 375));
        frameAdd.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                frameAddWindowClosed(evt);
            }
        });

        fieldAddMean.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Mean"));
        jScrollPane2.setViewportView(fieldAddMean);

        buttonAdd2.setText("Add");
        buttonAdd2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAdd2ActionPerformed(evt);
            }
        });

        labelWord.setText("Word");

        buttonCloseAdd.setText("Close");
        buttonCloseAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCloseAddActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout frameAddLayout = new javax.swing.GroupLayout(frameAdd.getContentPane());
        frameAdd.getContentPane().setLayout(frameAddLayout);
        frameAddLayout.setHorizontalGroup(frameAddLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, frameAddLayout.createSequentialGroup()
                        .addContainerGap(33, Short.MAX_VALUE)
                        .addGroup(frameAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 409,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(frameAddLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(frameAddLayout.createSequentialGroup().addComponent(labelWord)
                                                .addGap(29, 29, 29).addComponent(fieldAddWord,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 341,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(frameAddLayout.createSequentialGroup()
                                                .addComponent(buttonAdd2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(32, 32, 32).addComponent(buttonCloseAdd,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 69,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(22, 22, 22)));
        frameAddLayout.setVerticalGroup(frameAddLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(frameAddLayout.createSequentialGroup().addGap(17, 17, 17)
                        .addGroup(frameAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(fieldAddWord, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(labelWord))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(frameAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(buttonAdd2, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonCloseAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 39,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

        jScrollPane2.getAccessibleContext().setAccessibleName("");
        jScrollPane2.getAccessibleContext().setAccessibleDescription("");
        jScrollPane2.getAccessibleContext().setAccessibleParent(frameMean);

        frameSetting.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frameSetting.setTitle("Settings");
        frameSetting.setAlwaysOnTop(true);
        frameSetting.setLocation(new java.awt.Point(200, 100));
        frameSetting.setUndecorated(true);
        frameSetting.setSize(new java.awt.Dimension(400, 200));
        frameSetting.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                frameSettingWindowClosed(evt);
            }
        });

        panelVoice.setBorder(javax.swing.BorderFactory.createTitledBorder("Voice"));

        buttonGroup1.add(button1);
        button1.setSelected(true);
        button1.setText("Female");
        button1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                button1ItemStateChanged(evt);
            }
        });

        buttonGroup1.add(button2);
        button2.setText("Male");
        button2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                button1ItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout panelVoiceLayout = new javax.swing.GroupLayout(panelVoice);
        panelVoice.setLayout(panelVoiceLayout);
        panelVoiceLayout.setHorizontalGroup(panelVoiceLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelVoiceLayout.createSequentialGroup().addGap(70, 70, 70).addComponent(button1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
                        .addComponent(button2).addGap(82, 82, 82)));
        panelVoiceLayout
                .setVerticalGroup(panelVoiceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                panelVoiceLayout.createSequentialGroup().addContainerGap(22, Short.MAX_VALUE)
                                        .addGroup(panelVoiceLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(button1).addComponent(button2))
                                        .addGap(36, 36, 36)));

        buttonCloseSetting.setText("Close");
        buttonCloseSetting.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCloseSettingActionPerformed(evt);
            }
        });

        buttonAboutUs.setText("About Us");
        buttonAboutUs.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        buttonAboutUs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAboutUsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout frameSettingLayout = new javax.swing.GroupLayout(frameSetting.getContentPane());
        frameSetting.getContentPane().setLayout(frameSettingLayout);
        frameSettingLayout.setHorizontalGroup(frameSettingLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        frameSettingLayout.createSequentialGroup().addContainerGap()
                                .addComponent(panelVoice, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        frameSettingLayout.createSequentialGroup().addGap(28, 28, 28)
                                .addComponent(buttonAboutUs, javax.swing.GroupLayout.PREFERRED_SIZE, 81,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(buttonCloseSetting).addGap(31, 31, 31)));
        frameSettingLayout.setVerticalGroup(frameSettingLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(frameSettingLayout.createSequentialGroup().addGap(24, 24, 24)
                        .addComponent(panelVoice, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(frameSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(buttonAboutUs, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonCloseSetting, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(23, Short.MAX_VALUE)));

        frameCo.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frameCo.setTitle("Author");
        frameCo.setAlwaysOnTop(true);
        frameCo.setLocation(new java.awt.Point(200, 100));
        frameCo.setSize(new java.awt.Dimension(433, 255));
        frameCo.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                frameCoWindowClosed(evt);
            }
        });

        jLabel3.setBackground(new java.awt.Color(0, 102, 102));
        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Dictionary version 1.0");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Trn ?c Ton");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Phm Minh ?c");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Nguyn ?nh Phi");
        jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Phm Th Thu H?ng");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Trnh Vn Thi");
        jLabel8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout frameCoLayout = new javax.swing.GroupLayout(frameCo.getContentPane());
        frameCo.getContentPane().setLayout(frameCoLayout);
        frameCoLayout.setHorizontalGroup(frameCoLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        frameCoLayout.setVerticalGroup(frameCoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(frameCoLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3).addGap(24, 24, 24).addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel7,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dictionary English VietNam");
        setBackground(new java.awt.Color(255, 51, 0));
        setLocation(new java.awt.Point(200, 100));
        setResizable(false);
        setType(java.awt.Window.Type.POPUP);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        comboBoxEV.setBackground(new java.awt.Color(240, 240, 240));
        comboBoxEV.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        comboBoxEV.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "English-VietNamese", "VietNamese-English" }));
        comboBoxEV.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        comboBoxEV.setFocusable(false);
        comboBoxEV.setRequestFocusEnabled(false);
        comboBoxEV.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboBoxEVItemStateChanged(evt);
            }
        });

        fieldWord.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        fieldWord.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        fieldWord.setDoubleBuffered(true);
        fieldWord.setDragEnabled(true);
        fieldWord.setFocusCycleRoot(true);
        fieldWord.setFocusTraversalPolicyProvider(true);
        fieldWord.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fieldWordMouseClicked(evt);
            }
        });
        fieldWord.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                fieldWordKeyPressed(evt);
            }

            public void keyReleased(java.awt.event.KeyEvent evt) {
                fieldWordKeyReleased(evt);
            }
        });

        labelDic.setFont(new java.awt.Font("Times New Roman", 0, 48)); // NOI18N
        labelDic.setForeground(new java.awt.Color(255, 102, 0));
        labelDic.setText("Dictionary");

        labelAuthor.setForeground(new java.awt.Color(255, 102, 0));
        labelAuthor.setText("by HTTPD");

        buttonAdd.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/add.png"))); // NOI18N
        buttonAdd.setText("Add");
        buttonAdd.setBorder(null);
        buttonAdd.setFocusPainted(false);
        buttonAdd.setMargin(new java.awt.Insets(0, 14, 0, 14));
        buttonAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAddActionPerformed(evt);
            }
        });

        buttonSetting.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonSetting.setText("Settings");
        buttonSetting.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        buttonSetting.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSettingActionPerformed(evt);
            }
        });

        traonl.setText("Google Transl");
        traonl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                traonlActionPerformed(evt);
            }
        });

        comboBoxOnl.setBackground(new java.awt.Color(240, 240, 240));
        comboBoxOnl.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        comboBoxOnl.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Offline", "Online" }));
        comboBoxOnl.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        comboBoxOnl.setFocusable(false);
        comboBoxOnl.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboBoxOnlItemStateChanged(evt);
            }
        });

        buttonSpeech.setForeground(new java.awt.Color(255, 255, 255));
        buttonSpeech.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/speak.png"))); // NOI18N
        buttonSpeech.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSpeechActionPerformed(evt);
            }
        });

        buttonUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/Undo.png"))); // NOI18N
        buttonUndo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonUndoActionPerformed(evt);
            }
        });

        buttonFind.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dictionary/images/find.png"))); // NOI18N
        buttonFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFindActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainLayout = new javax.swing.GroupLayout(main);
        main.setLayout(mainLayout);
        mainLayout.setHorizontalGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainLayout.createSequentialGroup()
                        .addGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(buttonSetting, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(buttonAdd, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(traonl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(fieldWord, javax.swing.GroupLayout.PREFERRED_SIZE, 270,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(mainLayout.createSequentialGroup().addComponent(labelDic)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(labelAuthor))
                                        .addGroup(mainLayout.createSequentialGroup()
                                                .addComponent(comboBoxEV, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(comboBoxOnl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        91, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(mainLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(buttonSpeech, javax.swing.GroupLayout.PREFERRED_SIZE, 49,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(buttonFind, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                Short.MAX_VALUE))
                                .addComponent(buttonUndo, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 49,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));
        mainLayout.setVerticalGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonSetting, javax.swing.GroupLayout.PREFERRED_SIZE, 49,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
                                traonl, javax.swing.GroupLayout.PREFERRED_SIZE, 51,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainLayout.createSequentialGroup()
                        .addGroup(mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(labelDic).addComponent(labelAuthor))
                        .addGap(0, 33, Short.MAX_VALUE).addGroup(
                                mainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(mainLayout.createSequentialGroup().addGroup(mainLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(
                                                        comboBoxEV, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(comboBoxOnl, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        35, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(0, 0, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainLayout
                                                .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                                .addGroup(mainLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                                mainLayout.createSequentialGroup().addComponent(
                                                                        buttonUndo,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(6, 6, 6)
                                                                        .addComponent(
                                                                                buttonFind,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                38,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(buttonSpeech,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                38,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(5, 5, 5))
                                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                                mainLayout.createSequentialGroup().addComponent(
                                                                        fieldWord,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 76,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addContainerGap()))))));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(main, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                main, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //Add danh sach goi y vao list
    private void initData(ArrayList<String> list) {
        DefaultListModel<String> model = new DefaultListModel();
        System.out.println("\n" + list.size());
        list.stream().forEach((list1) -> {
            model.addElement(list1);
        });
        listEntries.setModel(model);

    }

    private void addUndo(String tmp) {
        if (recentWord.isEmpty() || !recentWord.getFirst().equals(tmp)) {
            recentWord.addFirst(tmp);
            while (recentWord.size() > 10) {
                recentWord.removeLast();
            }
        }
    }

    private void setEnableButton(boolean a) {
        buttonAdd.setEnabled(a);
        buttonEdit.setEnabled(a);
        buttonDelete.setEnabled(a);
        buttonSave.setEnabled(a);
    }

    private void showMean() {
        frameEntries.setVisible(false);
        String tmp = fieldWord.getText();

        if (!onl) {
            String temp1 = dic.search(new StringBuilder(tmp));
            if (temp1 != null) {
                frameMean.setVisible(true);
                frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
                fieldMean.setText(temp1);
                fieldMean.select(0, 0);
                buttonAdd.setEnabled(false);
                buttonSave.setEnabled(false);
                addUndo(tmp);
            } else {
                JOptionPane.showMessageDialog(null, "Cannot find any word!\n(Khng tm thy t no)");
            }
        } else {
            try {
                String temp2 = run.getResponse(tmp);
                if (temp2 != null) {
                    frameMean.setVisible(true);
                    frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
                    fieldMean.setText(temp2);
                    fieldMean.select(0, 0);
                    buttonAdd.setEnabled(false);
                    buttonSave.setEnabled(false);
                    addUndo(tmp);
                } else {
                    JOptionPane.showMessageDialog(null,
                            "Internet ca bn qu chm!!!\nHoc t bn tra khng tn ti!!");
                }
            } catch (IOException | ParseException ex) {
                Logger.getLogger(GUI_Main.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    private void buttonSpeechActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSpeechActionPerformed
        voice.speechText(fieldWord.getText());
    }//GEN-LAST:event_buttonSpeechActionPerformed

    private void fieldWordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldWordKeyReleased
        frameMean.setVisible(false);
        buttonSave.setEnabled(false);
        if (!onl) {
            String text = fieldWord.getText();
            if (!dic.wordSuggest(text).isEmpty()) {
                frameEntries.setVisible(true);
                frameEntries.setLocation(this.getX() + fieldWord.getX(), this.getY() + this.getHeight());
                initData(dic.wordSuggest(text));
                buttonAdd.setEnabled(true);
                fieldMean.setEditable(false);
                listEntries.setSelectedIndex(0);
            } else {
                frameEntries.setVisible(false);
                buttonAdd.setEnabled(true);
            }
        }
    }//GEN-LAST:event_fieldWordKeyReleased

    private void buttonAdd2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAdd2ActionPerformed
        if (dic.add(new StringBuilder(fieldAddWord.getText()), fieldAddMean.getText())) {
            this.setEnabled(true);
            frameAdd.dispose();
        } else {
            JOptionPane.showMessageDialog(null,
                    "Thao tc tht bi! T va thm  c trong t in!!!!!");
        }
    }//GEN-LAST:event_buttonAdd2ActionPerformed

    private void frameAddWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_frameAddWindowClosed
        this.setEnabled(true);
    }//GEN-LAST:event_frameAddWindowClosed

    private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed
        int click = JOptionPane.showConfirmDialog(null,
                "Bn c chc chn mun xa t : " + fieldWord.getText());
        if (click == JOptionPane.YES_OPTION) {
            dic.delete(new StringBuilder(fieldWord.getText()));
        }
        frameMean.dispose();
    }//GEN-LAST:event_buttonDeleteActionPerformed

    private void comboBoxEVItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBoxEVItemStateChanged
        recentWord.clear();
        fieldWord.setText(null);
        frameMean.setVisible(false);
        frameEntries.setVisible(false);
        if (!onl) { //tra tu offline
            if (comboBoxEV.getSelectedIndex() == 1) {
                dic = dicVE;
                buttonSpeech.setEnabled(false);
            } else {
                dic = dicEV;
                buttonSpeech.setEnabled(true);
            }
        } else { //Tra tu onl
            if (comboBoxEV.getSelectedIndex() == 1) {
                run.setDestFrom("vi", "eng");
                buttonSpeech.setEnabled(false);
            } else {
                run.setDestFrom("eng", "vi");
                buttonSpeech.setEnabled(true);
            }
        }
    }//GEN-LAST:event_comboBoxEVItemStateChanged

    private void buttonEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditActionPerformed
        fieldMean.setEditable(true);
        buttonSave.setEnabled(true);
    }//GEN-LAST:event_buttonEditActionPerformed

    private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
        int click = JOptionPane.showConfirmDialog(null, "Bn c chc chn mun lu thay i");
        if (click == JOptionPane.YES_OPTION) {
            dic.replace(new StringBuilder(fieldWord.getText()), new StringBuilder(fieldMean.getText()));
        }
        frameMean.dispose();
        buttonSave.setEnabled(false);
    }//GEN-LAST:event_buttonSaveActionPerformed

    private void buttonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExitActionPerformed
        frameMean.dispose();
        buttonAdd.setEnabled(true);
    }//GEN-LAST:event_buttonExitActionPerformed

    private void button1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_button1ItemStateChanged
        if (evt.getSource() == button1) {
            voice.setVoice("mbrola_us1");
        }
        if (evt.getSource() == button2) {
            voice.setVoice("mbrola_us2");
        }
    }//GEN-LAST:event_button1ItemStateChanged

    private void frameSettingWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_frameSettingWindowClosed
        this.setEnabled(true);
    }//GEN-LAST:event_frameSettingWindowClosed

    private void buttonCloseSettingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseSettingActionPerformed
        this.setEnabled(true);
        frameSetting.dispose();
    }//GEN-LAST:event_buttonCloseSettingActionPerformed

    private void frameCoWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_frameCoWindowClosed
        this.setEnabled(true);
    }//GEN-LAST:event_frameCoWindowClosed

    private void buttonCloseAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseAddActionPerformed
        this.setEnabled(true);
        frameAdd.dispose();
    }//GEN-LAST:event_buttonCloseAddActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        try {
            dicVE.outToFile("src/dictionary/data/VietEng.txt");
            dicEV.outToFile("src/dictionary/data/EngViet.txt");
        } catch (IOException ex) {
            Logger.getLogger(GUI_Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_formWindowClosing

    private void buttonUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoActionPerformed
        if (!recentWord.isEmpty()) {
            fieldWord.setText(recentWord.getFirst());
            frameMean.setVisible(true);
            frameEntries.setVisible(false);
            frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
            if (!onl) {
                fieldMean.setText(dic.search(new StringBuilder(recentWord.getFirst())));
            } else {
                try {
                    fieldMean.setText(run.getResponse(recentWord.getFirst()));
                } catch (IOException | ParseException ex) {
                    Logger.getLogger(GUI_Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            fieldMean.select(0, 0);
            buttonAdd.setEnabled(false);
            buttonSave.setEnabled(false);
            recentWord.removeFirst();
        }
    }//GEN-LAST:event_buttonUndoActionPerformed

    private void fieldWordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldWordKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            showMean();
        }

        if (!onl && (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP)) {
            listEntries.requestFocus();
        }

        if (evt.getKeyCode() == KeyEvent.VK_F1) {
            if (comboBoxEV.getSelectedIndex() == 0)
                voice.speechText(fieldWord.getText());
        }
    }//GEN-LAST:event_fieldWordKeyPressed

    private void listEntriesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listEntriesKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            fieldWord.setText(listEntries.getSelectedValue().toString());
            frameEntries.dispose();
            frameMean.setVisible(true);
            String tmp = fieldWord.getText();
            fieldMean.setText(dic.search(new StringBuilder(tmp)));
            fieldMean.select(0, 0);
            frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
            buttonAdd.setEnabled(false);
            buttonSave.setEnabled(false);
            if (recentWord.isEmpty() || !recentWord.getFirst().equals(tmp)) {
                recentWord.addFirst(tmp);
                while (recentWord.size() > 10) {
                    recentWord.removeLast();
                }
            }
        }
        if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            fieldWord.requestFocus();
        }
    }//GEN-LAST:event_listEntriesKeyPressed

    private void listEntriesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listEntriesMouseClicked
        fieldWord.setText(listEntries.getSelectedValue().toString());
        frameEntries.dispose();
        frameMean.setVisible(true);
        String tmp = fieldWord.getText();
        fieldMean.setText(dic.search(new StringBuilder(tmp)));
        fieldMean.select(0, 0);
        frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
        buttonAdd.setEnabled(false);
        buttonSave.setEnabled(false);
        if (recentWord.isEmpty() || !recentWord.getFirst().equals(tmp)) {
            recentWord.addFirst(tmp);
            while (recentWord.size() > 10) {
                recentWord.removeLast();
            }
        }
    }//GEN-LAST:event_listEntriesMouseClicked

    private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed
        this.setEnabled(false);
        frameAdd.setVisible(true);
    }//GEN-LAST:event_buttonAddActionPerformed

    private void buttonAboutUsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAboutUsActionPerformed
        this.setEnabled(false);
        frameCo.setVisible(true);
    }//GEN-LAST:event_buttonAboutUsActionPerformed

    private void buttonSettingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSettingActionPerformed
        this.setEnabled(false);
        frameSetting.setVisible(true);
    }//GEN-LAST:event_buttonSettingActionPerformed

    private void fieldMeanKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldMeanKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            fieldWord.requestFocus();
        }
    }//GEN-LAST:event_fieldMeanKeyPressed

    private void traonlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_traonlActionPerformed
        MyBrowser.main();
    }//GEN-LAST:event_traonlActionPerformed

    private void comboBoxOnlItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBoxOnlItemStateChanged
        fieldWord.setText(null);
        frameMean.setVisible(false);
        frameEntries.setVisible(false);
        if (comboBoxOnl.getSelectedIndex() == 0) {
            onl = false;
            setEnableButton(true);
        } else {
            onl = true;
            setEnableButton(false);
        }
        if (comboBoxEV.getSelectedIndex() == 1) {
            run.setDestFrom("vi", "eng");
            buttonSpeech.setEnabled(false);
        } else {
            run.setDestFrom("eng", "vi");
            buttonSpeech.setEnabled(true);
        }
    }//GEN-LAST:event_comboBoxOnlItemStateChanged

    private void buttonFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFindActionPerformed
        showMean();
    }//GEN-LAST:event_buttonFindActionPerformed

    private void fieldWordMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fieldWordMouseClicked
        frameMean.setVisible(false);
        if (!onl) {
            buttonAdd.setEnabled(true);
        }
    }//GEN-LAST:event_fieldWordMouseClicked

    /**
     * @param args the command line arguments
     * @throws javax.swing.UnsupportedLookAndFeelException
     */
    public static void main(String args[]) throws UnsupportedLookAndFeelException {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI_Main.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            try {
                new GUI_Main().setVisible(true);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(GUI_Main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(GUI_Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton button1;
    private javax.swing.JRadioButton button2;
    private javax.swing.JButton buttonAboutUs;
    private javax.swing.JButton buttonAdd;
    private javax.swing.JButton buttonAdd2;
    private javax.swing.JButton buttonCloseAdd;
    private javax.swing.JButton buttonCloseSetting;
    private javax.swing.JButton buttonDelete;
    private javax.swing.JButton buttonEdit;
    private javax.swing.JButton buttonExit;
    private javax.swing.JButton buttonFind;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonSave;
    private javax.swing.JButton buttonSetting;
    private javax.swing.JButton buttonSpeech;
    private javax.swing.JButton buttonUndo;
    private javax.swing.JComboBox comboBoxEV;
    private javax.swing.JComboBox comboBoxOnl;
    private javax.swing.JEditorPane fieldAddMean;
    private javax.swing.JTextField fieldAddWord;
    private javax.swing.JEditorPane fieldMean;
    private javax.swing.JTextField fieldWord;
    private javax.swing.JFrame frameAdd;
    private javax.swing.JFrame frameCo;
    private javax.swing.JFrame frameEntries;
    private javax.swing.JFrame frameMean;
    private javax.swing.JFrame frameSetting;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel labelAuthor;
    private javax.swing.JLabel labelDic;
    private javax.swing.JLabel labelWord;
    private javax.swing.JList listEntries;
    private javax.swing.JPanel main;
    private javax.swing.JPanel panelVoice;
    private javax.swing.JButton traonl;
    // End of variables declaration//GEN-END:variables
}