Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6587965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:59:11+00:00 2026-05-25T16:59:11+00:00

Basically I want to make it so when the user types into the textfield

  • 0

Basically I want to make it so when the user types into the textfield /attack animal it does the attack method and takes animal as a parameter. So if player typed /attack foo it do player.attack(foo). I already have methods that perform chat so I know which player is doing the chat. I just need to know how to reconize what comes after the /attack and take it as a parameter for player.attack() which takes a Player object as an argument. These are my methods that receive input:

public void actionPerformed(ActionEvent textBox) {
        String text = textField.getText();
        player.chat(text);
}

Which is in my Gui class, and:

public void chat(String chat){
    playerGui.printText(this.getName() + ": " + chat);
    playerGui.textField.selectAll();
}

Which is in the player class. A gui instance is passed to Player() which creates the variable playerGui.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:59:12+00:00Added an answer on May 25, 2026 at 4:59 pm

    You’ll have to tweak this to fit the syntax you want the user to use, but you would probably want to change your actionPerformed method to check for the different actions the user can perform, rather than just chatting.

    public void actionPerformed(ActionEvent textBox) { 
        String text = textField.getText();
        String command = text.substring(0, text.indexOf(" "));
        String args = text.substring(text.indexOf(" ") + 1);
        switch (command) {
            case "chat":
                // Pass everything but the command
                player.chat(args);
                break;
            case "/attack":
                player.attack(args);
                break;
            default:
                // Handle bad user input
        }
    }
    

    You will still have to verify that you are getting the right kind of arguments for each command, and I didn’t put in anything safeguard against null pointers or out-of-bounds with the string functions, but hopefully that will get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a site where there user can basically navigate the web
I want to make an application witch involves logging into google. It is basically
I basically want to make things easier by just looping LinkButtons instead of making
Basically I want to make sure I will always get the computer's name rather
Basically I want to make simple toggle program (that will be mapped to some
Basically, I want to make clicking anywhere on a page except in an input
I basically want to use link_to to link to the index method of a
Basically I have a site where I want the user to input something, have
I want to create a method like example below to make sure that a
Basically what I want to do is allow a user to type in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.