Commit 201e91ff authored by marc.sheppard's avatar marc.sheppard

Add new file

parent 3510724a
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
* GUI code
*
* @author Marc.
* Created 17 Nov 2019.
*/
public class GUI {
private int input_language = 0, output_language = 0;
private JFrame frame = new JFrame("GUI");
private Panel panel = new Panel();
private JLabel input_label = new JLabel("Input languge");
private JLabel output_label = new JLabel("output languge");
private JLabel in_label = new JLabel("In:");
private JLabel out_label = new JLabel("out:");
private JButton input_english_button = new JButton("English");
private JButton input_french_button = new JButton("French");
private JButton input_german_button = new JButton("German");
private JButton output_english_button = new JButton("English");
private JButton output_french_button = new JButton("French");
private JButton output_german_button = new JButton("German");
private JTextField input_textbox = new JTextField(12);
private JTextArea output_text = new JTextArea(1,12);
public GUI() {
//setup window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(350,150);
panel.add(input_label);
panel.add(input_english_button);
panel.add(input_french_button);
panel.add(input_german_button);
panel.add(output_label);
panel.add(output_english_button);
panel.add(output_french_button);
panel.add(output_german_button);
panel.add(in_label);
panel.add(input_textbox);
panel.add(out_label);
panel.add(output_text);
frame.add(panel);
frame.setVisible(true);
//what the buttons do when pressed
input_english_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { input_language = 0; }
});
input_french_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { input_language = 1; }
});
input_german_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { input_language = 2; }
});
output_english_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { output_language = 0; }
});
output_french_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { output_language = 1; }
});
output_german_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { output_language = 2; }
});
}
//update output text
public void updateText(String text) {
output_text.setText(text);
}
//returns text typed into textbox
public String getTextInput() { return input_textbox.getText(); }
//returns an int corresponding to the input language (0 = English, 1 = French, 2 = German)
public int getInputLanguage() { return input_language; }
//returns an int corresponding to the output language (0 = English, 1 = French, 2 = German)
public int getOutputLanguage() { return output_language; }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment