import javax.swing.JFrame;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Random;
import java.applet.Applet;
import java.applet.AudioClip;
////////////////////////////////////
// class for surface of tab "Lernen"
////////////////////////////////////
public class ClientLearn extends JFrame {
//////////////////////
// declaring instances
//////////////////////
private Border border_loweredEtched;
private JPanel panel_statusBar = new JPanel();
private JPanel panel_content = new JPanel();
private ImageIcon imageicon_changePackage = new ImageIcon(ClientLearn.class.getResource("images/client_iconChangePackage.gif"));
private ImageIcon imageicon_pronounciation = new ImageIcon(ClientLearn.class.getResource("images/client_iconPronounciation.gif"));
private ImageIcon imageicon_check = new ImageIcon(ClientLearn.class.getResource("images/client_iconCheck.gif"));
private ImageIcon imageicon_nextWord = new ImageIcon(ClientLearn.class.getResource("images/client_iconNextWord.gif"));
private ImageIcon imageicon_reverseQuery = new ImageIcon(ClientLearn.class.getResource("images/client_iconReverseQuery.gif"));
public JButton button_changePackage = new JButton(imageicon_changePackage);
private JButton button_reverseQuery = new JButton(imageicon_reverseQuery);
private JButton button_pronounciation = new JButton("Aussprache", imageicon_pronounciation);
private JButton button_memorize = new JButton("Merken");
private JButton button_check = new JButton("Prüfen", imageicon_check);
private JButton button_nextWord = new JButton("Nächste Vokabel", imageicon_nextWord);
private JLabel label_package = new JLabel("Paket:");
private JLabel label_status = new JLabel("Gelernt: 0%");
private JLabel label_hundredPercent = new JLabel("100%");
private JLabel label_sourceLanguage = new JLabel("Vokabel:");
private JLabel label_destinationLanguage = new JLabel("Bedeutung:");
private JLabel label_imageContainer = new JLabel();
private JTextField textfield_package = new JTextField();
private JProgressBar progressbar_status = new JProgressBar();
private JTextArea textarea_sourceLanguage = new JTextArea();
private JTextArea textarea_destinationLanguage = new JTextArea();
private ImageIcon imageicon_correct = new ImageIcon(ClientLearn.class.getResource("images/client_correct.gif"));
private ImageIcon imageicon_incorrect = new ImageIcon(ClientLearn.class.getResource("images/client_incorrect.gif"));
private ImageIcon imageicon_dummy = new ImageIcon(ClientLearn.class.getResource("images/client_dummy.gif"));
private JScrollPane scrollpane_sourceLanguage = new JScrollPane(textarea_sourceLanguage);
private JScrollPane scrollpane_destinationLanguage = new JScrollPane(textarea_destinationLanguage);
private AudioClip[] audioclip_correct = new AudioClip[3];
private AudioClip[] audioclip_incorrect = new AudioClip[2];
private AudioClip audioclip_test;
private Container container_learn;
private ClientMain clientMain;
private int int_counterOfPackageContent;
private ArrayList arraylist_memorizedWords;
private ArrayList arraylist_answers;
//////////////
// constructor
//////////////
public ClientLearn(Container container_learn, ClientMain clientMain) {
////////////////////
// set up parameters
////////////////////
this.container_learn = container_learn;
this.clientMain = clientMain;
////////////////
// set up panels
////////////////
border_loweredEtched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
panel_statusBar.setBounds(5, 10, 495, 45);
panel_content.setBounds(5, 60, 495, 195);
panel_statusBar.setBorder(border_loweredEtched);
panel_content.setBorder(border_loweredEtched);
panel_statusBar.setLayout(null);
panel_content.setLayout(null);
////////////////////
// set up components
////////////////////
label_package.setBounds(10, 10, 30, 25);
textfield_package.setBounds(45, 10, 140, 25);
button_changePackage.setBounds(190, 10, 23, 25);
button_reverseQuery.setBounds(218, 10, 23, 25);
label_status.setBounds(250, 10, 60, 25);
progressbar_status.setBounds(310, 10, 145, 25);
label_hundredPercent.setBounds(460, 10, 35, 25);
label_sourceLanguage.setBounds(10, 5, 50, 25);
scrollpane_sourceLanguage.setBounds(95, 7, 202, 55);
label_destinationLanguage.setBounds(10, 65, 55, 25);
scrollpane_destinationLanguage.setBounds(95, 67, 360, 65);
button_pronounciation.setBounds(305, 7, 150, 25);
button_memorize.setBounds(305, 37, 150, 25);
button_check.setBounds(95, 137, 150, 25);
button_nextWord.setBounds(305, 137, 150, 25);
label_imageContainer.setBounds(10, 88, 80, 85);
////////////////////////
// set up textarea fonts
////////////////////////
textarea_sourceLanguage.setFont(new Font("Arial", Font.PLAIN, 11));
textarea_destinationLanguage.setFont(new Font("Arial", Font.PLAIN, 11));
///////////////////////////
// add dummy image to label
///////////////////////////
label_imageContainer.setIcon(imageicon_dummy);
/////////////////////////
// initialize sound clips
/////////////////////////
/*audioclip_correct[0] = Applet.newAudioClip(ClientLearn.class.getResource("sounds/applause1.wav"));
audioclip_correct[1] = Applet.newAudioClip(ClientLearn.class.getResource("sounds/applause2.wav"));
audioclip_correct[2] = Applet.newAudioClip(ClientLearn.class.getResource("sounds/applause3.wav"));
audioclip_incorrect[0] = Applet.newAudioClip(ClientLearn.class.getResource("sounds/cough1.wav"));
audioclip_incorrect[1] = Applet.newAudioClip(ClientLearn.class.getResource("sounds/cough2.wav"));
AudioClip audioclip_test = Applet.newAudioClip(ClientLearn.class.getResource("sounds/applause1.wav"));
audioclip_test.play();*/
try {
AudioClip audioclip_test = Applet.newAudioClip(ClientLearn.class.getResource("sounds/applause1.wav"));
audioclip_test.play();
}
catch(Exception e) {
System.err.println(e.toString());
}
////////////////////////////////////
// add components to specific panels
////////////////////////////////////
panel_statusBar.add(label_package);
panel_statusBar.add(textfield_package);
panel_statusBar.add(button_changePackage);
panel_statusBar.add(button_reverseQuery);
panel_statusBar.add(label_status);
panel_statusBar.add(progressbar_status);
panel_statusBar.add(label_hundredPercent);
panel_content.add(label_sourceLanguage);
panel_content.add(scrollpane_sourceLanguage);
panel_content.add(button_pronounciation);
panel_content.add(button_memorize);
panel_content.add(label_destinationLanguage);
panel_content.add(scrollpane_destinationLanguage);
panel_content.add(button_check);
panel_content.add(button_nextWord);
panel_content.add(label_imageContainer);
///////////////////
// set up mnemonics
///////////////////
button_pronounciation.setMnemonic(KeyEvent.VK_A);
button_memorize.setMnemonic(KeyEvent.VK_M);
button_check.setMnemonic(KeyEvent.VK_P);
button_nextWord.setMnemonic(KeyEvent.VK_N);
//////////////////
// set up tooltips
//////////////////
button_changePackage.setToolTipText("<html>Wählen Sie ein <b>anderes Paket</b></html>");
button_reverseQuery.setToolTipText("<html>Prüfen Sie <b>in umgekehrter Beziehung</b></html>");
button_pronounciation.setToolTipText("<html>Hören Sie die <b>Aussprache dieser Vokabel</b></html>");
button_memorize.setToolTipText("<html>Setzen Sie diese Vokabel <b>auf Ihren Merkzettel</b></html>");
button_check.setToolTipText("<html><b>Prüfen</b> Sie auf Korrektheit</html>");
button_nextWord.setToolTipText("<html><b>Später</b> noch einmal abfragen</html>");
///////////////////////////////
// disable or enable components
///////////////////////////////
textfield_package.setEditable(false);
textarea_sourceLanguage.setEditable(false);
textarea_sourceLanguage.setEnabled(false);
textarea_destinationLanguage.setEditable(false);
textarea_destinationLanguage.setEnabled(false);
button_changePackage.setEnabled(false);
button_reverseQuery.setEnabled(false);
button_pronounciation.setEnabled(false);
button_memorize.setEnabled(false);
button_check.setEnabled(false);
button_nextWord.setEnabled(false);
//////////////////////////
// add panels to container
//////////////////////////
container_learn.add(panel_statusBar);
container_learn.add(panel_content);
////////////////////////
// set up event handling
////////////////////////
button_changePackage.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_changePackage();
}
});
button_reverseQuery.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_reverseQuery();
}
});
button_pronounciation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_pronounciation();
}
});
button_memorize.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_memorize();
}
});
button_check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_check();
}
});
button_nextWord.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client_nextWord();
}
});
}
[... viele methoden ...]