This is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class prueba1 extends JFrame {
JButton English,Spanish;
JTextField textTranslate,resultTranslate;
public prueba1(){
setTitle("Translate");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1,2));
textTranslate = new JTextField();
resultTranslate = new JTextField();
p1.add(textTranslate);
p1.add(resultTranslate);
add(p1, BorderLayout.CENTER);
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(1,2));
English = new JButton ("English - Spanish");
Spanish = new JButton("Spanish - English");
p2.add(English);
English.addActionListener(new OyenteBoton());
p2.add(Spanish);
add(p2, BorderLayout.SOUTH);
setSize(400, 250);
setVisible(true);
}
public static void main (String args[])throws Exception {
prueba1 prueba1 = new prueba1();
}
class OyenteBoton implements ActionListener {
public void actionPerformed(ActionEvent e){
Translate.setClientId("xxxxxxxxxxxx");
Translate.setClientSecret("xxxxxxxxxxxxxxxxxxxxxx");
String valor = textTranslate.getText();
String translatedText = Translate.execute(valor, Language.SPANISH, Language.ENGLISH); //<---- the error is here
resultTranslate.setText(translatedText);
}
}
}
this is the error:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type Exception
at prueba1$OyenteBoton.actionPerformed(prueba1.java:70)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)