I am making a text based game in Java. I have a text field, enter button, and a label.
What code do i use to scan the text field once the button is clicked and respond?
So that if I type in (launch missile) the label should say (missile launched).
I will be listening to a button actionperformed
or maybe a mouseclick event . Something like this
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (Text field says: launch missile)
{print on label:Missile launched}
or
if (text field says: invade)
{Print on label: Invasion started}
try
JButton launch=new JButton(new AbstractAction("Launch")
{
@Override
public void actionPerformed(ActionEvent e)
{
yourLabel.setText("Missile Launched");
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.