samedi 5 mars 2016

Creating arrays that translate from English to Spanish

I need to set up three one-dimensional arrays to contain the equivalent English and other-language-of-your-choice nouns, and the images of those objects. When I open the applet nothing happens at all. I'm not sure how close I am with my coding. I really wasn't sure how to accomplish this but this is what I came up with. I haven't added any images yet. This is my code so far.

import java.util.Scanner;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ButtonArray extends JApplet implements ActionListener

{
    JButton button;

    JTextField textfield;

    String textFieldInput = "Enter a word from the dictionary";

    int fromString;

    String[] english={"hambuger", "pen", "house"};
    String[] spanish={"hamburguesa", "boligrafo", "casa"};
    String[] picture={"image1", "image2", "image3"};


    public static void main(String[] args){

        String[] english={"hambuger", "pen", "house"};
        String[] spanish={"hamburguesa", "boligrafo", "casa"};
        String[] picture={"image1", "image2", "image3"};
        Scanner scan = new Scanner(System.in);
        System.out.println("English word to translate: ");
        String temp = scan.next();

    } 
    public void init() {

        Scanner scan = new Scanner(System.in);
        System.out.println("English word to translate: ");
        String temp = scan.next();

        this.setLayout(null);

        textfield = new JTextField("Enter a word from the dictionary");
        this.add(textfield);
        textfield.setBounds(10, 10, 400, 20);

        button = new JButton("Translate");
        this.add(button);
        button.addActionListener(this);
        button.setBounds(50, 50, 150, 20);
    }


     public void actionPerformed(ActionEvent event) {


         Scanner scan = new Scanner(System.in);
         String temp = scan.next();

         for(int i=0; i < english.length; i++){
             if(temp == english[i]){
                 System.out.println(spanish[i]);
                 System.out.println(picture[i]);
                }
             if(i==english.length || temp != english[i]){
                    System.out.println("Word is not found");
                }  
           }
        } 
        public void paint(Graphics g) {
            super.paint(g);

            g.drawString("hamburger", 300, 250);
            g.drawString("pen", 300, 270);
            g.drawString("house", 300, 290);

            g.drawString("hamburguesa", 300, 250);
            g.drawString("boligrafo", 320, 270);
            g.drawString("casa", 340, 290);


    }
}

Aucun commentaire:

Enregistrer un commentaire