samedi 16 mai 2015

Using an actionListener and if statements to change a textfield

I'm working on this short section of code, I would like it to check for "Hello" and respond by either showing "bonjour" or "almost working". Is there a way to have this work and not be case sensitive? Is there a simple way to more words to translate without entering them into the code?

   JButton French = new JButton("French");
    French.setPreferredSize(new Dimension(200, 150));
    French.setFont(Font1);
    French.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (arg0.getSource()==French);
            //changing the above if to while crashes the program.
            if (Input.equals("Hello"))
            Output.setText("Bonjour!");
            else  {Output.setText("almost working");
        }
    }});

Aucun commentaire:

Enregistrer un commentaire