Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: simple translator GUI ??

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default simple translator GUI ??

    hi

    i wanna try how to program a simple GUI for translator Application

    i did the GUI but i need help about the idea of this code

    to translate between 2 languages

    my code is :

    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");
    	}
    }


    it's not completed

    i was searching via the net and i found GoogleAPI

    but to run the program you should be online

    and i want my program runs without connecting to the internet

    please help
    Last edited by sciences; March 1st, 2012 at 11:43 AM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: simple translator GUI ??

    Well, if you want to make your desktop application work without internet, you need to have the whole list of words in both languages and the relation between different words of two languages.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple translator GUI ??

    It is not possible to connect to google without the internet...
    As the previous poster indicated, the only way to achieve what you want is to somehow get all words from language1 and all words from language2 and store them locally on your workstation. You would then need some way of determining relationships between words (for example "jump" in english maps to "sauter" in french).

    With this information you would then need to generate some trees or hashmaps which allow you to get the word from language2 that maps to the word from language1 and vice-versa.

    Basically if all you want is to use your GUI to call google api functions, then you MUST have access to the internet. Short of that, you're pretty much stuck completely re-writting the google api functions you intend to use.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: simple translator GUI ??

    Well, rektiphyr, you can't see if it's the only solution.
    @sciences: There are many dictionaries available. You can either use the dictionary in order to get results.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: simple translator GUI ??

    thank you so much

    I searched over the internet and found a database for texts

    but if please help me how to start coding the dictionary

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: simple translator GUI ??

    Read the concept of HashMaps.

Similar Threads

  1. English to L33T Translator
    By eeengenious in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 28th, 2012, 07:19 AM
  2. Creating a slang translator
    By TFG in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 28th, 2011, 11:02 AM
  3. PigLatin translator help
    By Rusak in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2011, 07:53 AM
  4. Help with Pig Latin Translator...
    By jchan in forum AWT / Java Swing
    Replies: 3
    Last Post: September 28th, 2009, 02:54 PM
  5. Pig Latin Translator
    By BMN901 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 17th, 2009, 03:31 AM