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

  • Home
  • SEARCH
  • 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 9122483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:06:53+00:00 2026-06-17T06:06:53+00:00

Is this how to properly call a method from another method in java? Can

  • 0

Is this how to properly call a method from another method in java? Can someone describe how to create an overloaded method for attack that would allow me to run attack with a base attack modifier? actionPerformed is the method that is the controlling the submit actions of all the buttons that are instantiated in proper java swing style. The command is button dependent and the program is to help model the first fight of an rpg. The attack function calls all the boolean functions to receive various possibilities for the outcome of the button submission. The actionPerformed function should then call the damage function which should update the hp value in the Jtable. The code that demonstrates the functions described is attached. I need some assistance on code troubleshooting if anyone could help me it would be greatly appreciated.

public void actionPerformed(ActionEvent event) 
{
    String command = event.getActionCommand();

    this.getRows(table);

    rows = this.rows;

    firstRow = rows[0];

    lastRow = rows[1];

    if(command == "Shield Bash") {
        this.attack(firstRow, lastRow, command, table);
        damage = this.damage;
        this.damage(table, firstRow, damage);
    }else if(command == "Run Threw") {

    }else if(command == "React") {
        this.attack(firstRow, lastRow, command, table);
        damage = this.damage;
        this.damage(table, firstRow, damage);
    }else if (command == "Attack") {
        this.attack(firstRow, lastRow, command, table);
        damage = this.damage;
        this.damage(table, firstRow, damage);
    }else if (command == "Skill") {

    }else if (command == "Heal") {

    }else if (command == "Rest") {

    }else if (command == "Skulk") {

    }else {

    }

}

public boolean block (JTable table, int defendersRow) {
    defendersRow = this.defendersRow;
    blockChanceObject = table.getValueAt(defendersRow, 15);
    blockChance = (Integer) blockChanceObject;
    blockRoll = generator.nextInt(100) + 1;
    if(blockRoll < blockChance) {
        blocked = true;
    }
    return blocked;
}

public boolean fumble (JTable table, int attackersRow) {
     attackersRow = this.attackersRow;
     fumbleChanceObject = table.getValueAt(attackersRow, 7);
     fumbleChance = (Integer) fumbleChanceObject;
     int fumbleRoll = generator.nextInt(100) + 1;
     if (fumbleRoll < fumbleChance) {
         fumbled = true;
     }
     return fumbled;

}

public boolean dodge (JTable table, int defendersRow) {

    defendersRow = this.defendersRow;

    dodgeChanceObject = table.getValueAt(defendersRow,12);

    dodgeChance = (Integer) dodgeChanceObject;

    dodgeRoll = generator.nextInt(100) + 1;

    if (dodgeRoll < dodgeChance) {
        dodged = true;
    }

    return dodged;

}

public boolean critical (JTable table, int attackersRow, int attackRoll) {
    attackersRow = this.attackersRow;
    attackRoll = this.attackRoll;
    criticalChanceObject = table.getValueAt(attackersRow, 8);
    criticalChance = (Integer) criticalChanceObject;
    if (attackRoll >= criticalChance) {
        criticaled = true;
    }
    return criticaled;
}

public int[] getRows(JTable table) {    
    rows[0] = table.getSelectedRow();
    rowCount = table.getSelectedRowCount() - 1;
    rows[1] = rows[0] + rowCount;
    return rows;
}

public int attack(int firstRow, int lastRow, String command, JTable table) {
    command = this.command;
    firstRow = this.firstRow;
    lastRow = this.lastRow;
    table = this.table;

    if (command == "Bludgeon" || command == "React" || command == "ShieldBash") {
        attackersRow = this.lastRow;
        defendersRow = this.firstRow;
    }else if(command == "Attack" || command == "Skill") {
        attackersRow = this.firstRow;
        defendersRow = this.lastRow;
    }else {

    }

    this.fumble(table, attackersRow);
    if (fumbled == true) {
        outputString = "fumbled";
    }

    attackRoll = generator.nextInt(100) + 1;
    this.critical(table, attackersRow, attackRoll);
    if (criticaled == true) {
        outputString = "criticaled";
    }
    this.dodge(table, defendersRow);
    if (dodged == true) {
        outputString = "dodged";
    }
    this.block(table, defendersRow);
    if (blocked == true) {
        outputString = "blocked";
    }
    defenseRoll = generator.nextInt(100) + 1;
    attackBaseObject = table.getValueAt(attackersRow, 6);
    defenseBaseObject = table.getValueAt(defendersRow, 11);
    attackBase = (Integer) attackBaseObject;
    defenseBase = (Integer) defenseBaseObject;
    attack = attackRoll + attackBase;
    defense = defenseRoll + defenseBase;
    minDamageObject = table.getValueAt(attackersRow, 9);
    minDamage = (Integer) minDamageObject;
    maxDamageObject = table.getValueAt(attackersRow, 10);
    maxDamage = (Integer) maxDamageObject;
    damage = generator.nextInt((maxDamage - minDamage))+minDamage;
    if (criticaled == true) {
        damage = maxDamage * 2;
    }else if (attack >= (defense + 50)) {
        damage = damage * 2;
    }else if (attack >= defense) {
        damage = damage;
    }else {
        damage = 0;
    }
    this.outputSelection(outputString, attackersRow, defendersRow, table, command, damage);
    return damage;
}

private void damage(JTable table, int defendersRow, int damage) {
    damage = this.damage;
    defendersRow = this.defendersRow;
    hpObject = table.getValueAt(defendersRow, 3);
    hp = (Integer) hpObject;
    hp = hp - damage;
    table.setValueAt(hp, defendersRow, 3);
}

private void outputSelection(String outputString, int attackersRow, int defendersRow, JTable table, String command, int damage) {
  • 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-06-17T06:06:55+00:00Added an answer on June 17, 2026 at 6:06 am

    A couple of quick observations- do not compare strings using ==. Use the .equals method. Secondly, you don’t seem to be following an object oriented paradigm. You should probably create a couple of classes, design them properly and then go about your implementation.

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

Sidebar

Related Questions

Hello I am trying to call a method (fileReader) that is using openFileInput(filename) from
I hope I can explain this properly. I'm using flashDevelop for an avatar creation
Trying to figure out how I can do this properly. The print_r looks like
I can't for the life of me figure out how to do this properly.
How can I make this print properly without using two printf calls? char* second
CREATE OR REPLACE FUNCTION layer2layerAttribute RETURN VARCHAR2 AS /** * This function properly joins
I have a form (let's call it parent form), from which another always on
I used this tutorial http://delphi.about.com/od/kbthread/a/thread-gui.htm to create a class that asynchronously downloads a file
I've building a app right now that I'm trying to keep properly decoupled from
This code doesn't work propely: I call a function passing a variable What's the

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.