Problem with Classes and Variables in java

0

I created a class, inside it I want to call some methods but it has to be what is typed inside the JTextPanel, does anyone know how to do it?

This is my Choice class:

    public class Escolha {
public static String hey; //NAO EXISTE NO CÓDIGO É SO PRA DAR SENTINDO PRO PROXIMO CÓDIGO
    public static void Ola() {  


try {  

    Robot robot = new Robot();  
    robot.delay(5000);  
    robot.keyPress(KeyEvent.VK_O);  
    robot.keyPress(KeyEvent.VK_L);  
    robot.keyPress(KeyEvent.VK_A);    

} catch (AWTException e) {  
    e.printStackTrace();  
}
}'       

public static void Tchau() {  

    try {  

        Robot robot = new Robot();  
        robot.delay(5000);  
        robot.keyPress(KeyEvent.VK_T);  
        robot.keyPress(KeyEvent.VK_C);  
        robot.keyPress(KeyEvent.VK_H);  
        robot.keyPress(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_U);  

    } catch (AWTException e) {  
        e.printStackTrace();  
    }  
}'

In my program I have a Button:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Escolha.ola();
}                                        

It works, but I wanted to put a JtextField that which method will execute Ex1: (How is it working)

Ex2:(WhatIwantittodo)HereitreadstheJtextFieldandexecutestheChoose.OlaWhyisitWrittenWaveinthebox

Ex3:(WhatIwantittodo)HereitreadstheJtextFieldandperformstheChoose.Bye.Becauseit'swrittenbyeinthebox

Onesolutionwouldbe:

Stringt1=jTextField1.getText();if(t1=="Ola")
{
Escolha.ola();
}
if(t1=="tchau")
{
    Escolha.tchau;
}

But I did not want to create Multiple if's, would not it have another way?

    
asked by anonymous 28.05.2017 / 01:24

1 answer

0

Hi. Yes.

I've created a class to show an example: %pr_e%

import javax.swing.JOptionPane;

public class MyClass {     public void callMessage (String msg) {         JOptionPane.showMessageDialog (null, msg);     } }

And this is the method that calls the method "callMessage" in class "MyClass": %pr_e% With this, you can put as many parameters as you like.

    
28.05.2017 / 05:16