Question

Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

Simple java GUI language translator. English to Spanish, French, or German

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class translatorApp extends JFrame implements ActionListener {

   public static final int width = 500;
   public static final int height = 300;
   public static final int no_of_lines = 10;
   public static final int chars_per_line = 20;

   private JTextArea lan1;
   private JTextArea lan2;

   public static void main(String[] args){

       translatorApp gui = new translatorApp();
       gui.setVisible(true);

   }

   public translatorApp(){

       super("language translator");
       setSize(width, height);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLayout(new GridLayout(2,1));



       JPanel biggerPanel = new JPanel();
       biggerPanel.setLayout(new FlowLayout());
       biggerPanel.setBackground(Color.LIGHT_GRAY);




       lan1 = new JTextArea("enter source text here \n",no_of_lines,chars_per_line);
       lan1.setEditable(true);
       lan1.setLineWrap(true);
       biggerPanel.add(lan1);




       lan2 = new JTextArea(no_of_lines,chars_per_line);
       lan2.setEditable(true);
       lan2.setLineWrap(true);
       biggerPanel.add(lan2);


       add(biggerPanel);



       JPanel buttonsPanel = new JPanel();
       buttonsPanel.setLayout(new FlowLayout());
       buttonsPanel.setBackground(Color.LIGHT_GRAY);


       JButton translate = new JButton("translate!");
       translate.addActionListener(this);
       buttonsPanel.add(translate);


       JButton clear = new JButton("Clear");
       clear.addActionListener(this);
       buttonsPanel.add(clear);

       add(buttonsPanel);
   }

   public void actionPerformed(ActionEvent e){

       String buttonText = e.getActionCommand();

       if(buttonText.equals("translate!"))
           lan2.setText(lan2.getText());
       else if(buttonText.equals("Clear"))
           {
           lan1.setText("");
           lan2.setText("");
           }
           else
           lan2.setText("error occured");
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have highlighted the modified code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class translatorApp extends JFrame implements ActionListener {

public static final int width = 500;
public static final int height = 300;
public static final int no_of_lines = 10;
public static final int chars_per_line = 20;

private JTextArea lan1;
private JTextArea lan2;

public static void main(String[] args){

translatorApp gui = new translatorApp();
gui.setVisible(true);

}

public translatorApp(){

super("language translator");
setSize(width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new java.awt.GridLayout(2,1));

JPanel biggerPanel = new JPanel();
biggerPanel.setLayout(new FlowLayout());
biggerPanel.setBackground(Color.LIGHT_GRAY);

lan1 = new JTextArea("enter source text here \n",no_of_lines,chars_per_line);
lan1.setEditable(true);
lan1.setLineWrap(true);
biggerPanel.add(lan1);

lan2 = new JTextArea(no_of_lines,chars_per_line);
lan2.setEditable(true);
lan2.setLineWrap(true);
biggerPanel.add(lan2);

add(biggerPanel);

JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout());
buttonsPanel.setBackground(Color.LIGHT_GRAY);

JButton translate = new JButton("translate!");
translate.addActionListener(this);
buttonsPanel.add(translate);

JButton clear = new JButton("Clear");
clear.addActionListener(this);
buttonsPanel.add(clear);

add(buttonsPanel);
}

public void actionPerformed(ActionEvent e){

String buttonText = e.getActionCommand();

if(buttonText.equals("translate!"))
lan2.setText(lan2.getText());
else if(buttonText.equals("Clear"))
{
       lan1.setText("");
       lan2.setText("");
}
else
    lan2.setText("error occured");
}
}

Add a comment
Know the answer?
Add Answer to:
Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel titleLabel;       private JTextField titleTxtFd;       private JComboBox typeCmb;       private ButtonGroup ratingGP;       private JButton processBnt;       private JButton endBnt;       private JButton clearBnt;       private JTextArea entriesTxtAr;       private JRadioButton excellentRdBnt;       private JRadioButton veryGoodRdBnt;       private JRadioButton fairRdBnt;       private JRadioButton poorRdBnt;       private String ratingString;       private final String EXCELLENT = "Excellent";       private final String VERYGOOD = "Very Good";       private final String FAIR = "Fair";       private final String POOR = "Poor";       String...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show...

    In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...

  • Convert the following GUI application into an Applet. Do not delete any part of the GUI...

    Convert the following GUI application into an Applet. Do not delete any part of the GUI program, just comment out the part of the program not required. Another Java code is required // Java code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PizzaShopping extends JFrame { JCheckBox ckb[]; JLabel jlb1; JRadioButton radio[], radio1[]; static String[] pizzaToppings = "Tomato,Green peppper,Black olives,Mushrooms,Extra cheese,Pepproni,Sausage" .split(","); static String[] pizzaSizes = "Small: $6.50, Medium: $8.50, Large: $10".split(","); static String[] pizzatypes = "Thin Crust, Mediam...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • I want to extend this GUI application in java language. Thanks for the help in advance. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.Action...

    I want to extend this GUI application in java language. Thanks for the help in advance. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class FormWindow {     private JFrame frame;     /**      * Launch the application.      */     public static void main(String[] args) {         EventQueue.invokeLater(new Runnable() {             public void run() {                 try {                     FormWindow window = new FormWindow();                     window.frame.setVisible(true);                 } catch (Exception e) {                     e.printStackTrace();                 }             }         });     }     /**      * Create the application.      */     public FormWindow() {         initialize();    ...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT