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?