The program is simple, my instructions are as follows:
Write a GUI application that translates the Latin words to English. The window should have three buttons, one for each latin word. When the user clicks a button, the program displays the English translation in a label.
My error message reads:
Lab7.java:13: error: invalid method declaration; return type required
public LatinTranslatorGUI()
^
1 error
And finally, my code.
Code
import javax.swing.*;
import java.awt.event.*;
public class Lab7 extends JFrame
{
private JButton button1;
private JButton button2;
private JButton button3;
private JPanel panel;
private final int WINDOW_WIDTH = 320;
private final int WINDOW_HEIGHT = 70;
public LatinTranslatorGUI()
{
super("Latin Translator");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCLoseOperation(JFrame.EXIT_ON_CLOSE);
button1 = new JButton("Sinister");
button2 = new JButton("Dexter");
button3 = new JButton("Medium");
button1.addActionListener(new ButtonListener());
button2.addActionListener(new ButtonListener());
button3.addActionListener(new ButtonListener());
panel = new JPanel();
panel.add(button1);
panel.add(button2);
panel.add(button3);
add(panel);
setVisible(true);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button1)
JOptionPane.showMessageDialog(null, "Left");
else if (e.getSource() == button2)
JOptionPane.showMessageDialog(null, "Right");
else if (e.getSource() == button3)
JOptionPane.showMessageDialog(null, "Center");
}
public static void main(String[] args)
{
LatinTranslatorGUI latinTranslate = new LatinTranslatorGUI();
}
}
}