Hey, I’ve just about finished re-writing a program I did a little while ago so that I’ll easily be able to update it and that. The program is pretty much complete, but I’ve run into a few errors which I’m usually able to solve easily but for some reason I just can’t figure out what’s going on with them now. If anyone has a minute to do a quick check-over and see if you can find a fix please do so.
(Pastebin isn’t working for me at the moment, sorry for this wall of code…
import javax.swing.*;
import java.awt.event.*; //Needed for action event listeners for the buttons
public class DnDFormulator
{
public static void main(String args[])
{
Interface tempVariable = new Interface();
}
}
class Formulator
{
private int formulaMainAttribute = 0; //Main Attribute - Attack Formula
private int formulaWeaponRoll= 0; //Weapon Roll - Attack Formula
private int formulaPassiveBonusAttack = 0; //Passive Bonus - Attack Formula
private int formulaBaseDamage = 0; //Base Damage - Attack Formula
private int formulaConstitution = 0; //Constitution - Defence Formula
private int formulaArmor = 0; //Armor - Defense Formula
private int formulaPassiveBonusDefence = 0; //Passive Bonus - Defense Formula
private int formulaSpellDamage = 0; //Spell Damage - Magic Formula
private int formulaIntellect = 0; //private intellect - Magic Formula
private int formulaPassiveBonusMagic = 0; //Passive Bonus - Magic Formula
private int formulaSpellPower = 0; //Spell power - Magic Formula
private int formulaHealingPower = 0; //Healing Power = Magic Frmula
private double outputAttackFormula = 0.0; //Attack Formula Output
private double outputDefenceFormula= 0.0; //Defence Formula Output
private double outputMagicFormula = 0.0; //Magic Formula Output
private boolean formulaCriticalStrike = false; //Did you crit?
public Formulator()
{
}
//Formulas
public double attackFormula()
{
if ( formulaCriticalStrike == true )
outputAttackFormula = ( ( ( formulaMainAttribute/ 2 ) + formulaWeaponRoll + formulaPassiveBonusAttack + formulaBaseDamage ) * 2 );
else
outputAttackFormula = ( ( formulaMainAttribute/ 2 ) + formulaWeaponRoll + formulaPassiveBonusAttack + formulaBaseDamage);
return outputAttackFormula;
}
public double defenceFormula()
{
if ( formulaCriticalStrike == true )
outputDefenceFormula = ( ( (formulaConstitution/ 3) + formulaArmor + formulaPassiveBonusDefence ) * 2 );
else
outputDefenceFormula = ( (formulaConstitution / 3) + formulaArmor + formulaPassiveBonusDefence );
return outputDefenceFormula;
}
public double magicFormula(int formulaSpellOrHealingPower)
{
if (formulaSpellOrHealingPower == 0)
formulaSpellOrHealingPower = formulaHealingPower;
else
formulaSpellOrHealingPower = formulaSpellPower;
if ( formulaCriticalStrike == true )
outputMagicFormula = ( ( ( ( formulaSpellDamage + ( formulaIntellect / 2 ) ) * formulaPassiveBonusMagic ) * ( formulaSpellOrHealingPower / 2 ) ) * 2 );
else
outputMagicFormula = ( ( ( formulaSpellDamage + ( formulaIntellect / 2 ) ) * formulaPassiveBonusMagic ) * ( formulaSpellOrHealingPower / 2 ) );
return outputMagicFormula;
}
//Setters (Doesn't include the outputs because they will be calculated and set within this class)
public void formulaMainAttributeSetter(int x)
{
formulaMainAttribute = x;
}
public void formulaWeaponRollSetter(int x)
{
formulaWeaponRoll = x;
}
public void formulaPassiveBonusAttackSetter(int x)
{
formulaPassiveBonusAttack = x;
}
public void formulaBaseDamageSetter(int x)
{
formulaBaseDamage = x;
}
public void formulaConstitutionSetter(int x)
{
formulaConstitution = x;
}
public void formulaArmorSetter(int x)
{
formulaArmor = x;
}
public void formulaPassiveBonusDefenceSetter(int x)
{
formulaPassiveBonusDefence = x;
}
public void formulaSpellDamageSetter(int x)
{
formulaSpellDamage = x;
}
public void formulaIntellectSetter(int x)
{
formulaIntellect = x;
}
public void formulaPassiveBonusMagicSetter(int x)
{
formulaPassiveBonusMagic = x;
}
public void formulaSpellPowerSetter(int x)
{
formulaSpellPower = x;
}
public void formulaHealingPowerSetter(int x)
{
formulaHealingPower = x;
}
public void formulaCriticalStrikeSetter(boolean x)
{
formulaCriticalStrike = x;
}
}
class Interface extends JFrame
{
private JLabel attackFormulaLabelOne = new JLabel("Main Attribute");
private JLabel attackFormulaLabelTwo = new JLabel("Weapon Roll");
private JLabel attackFormulaLabelThree = new JLabel("Passive Bonus");
private JLabel attackFormulaLabelFour = new JLabel("Base Damage");
private JLabel defenceFormulaLabelOne = new JLabel("Constitution");
private JLabel defenceFormulaLabelTwo = new JLabel("Armor");
private JLabel defenceFormulaLabelThree = new JLabel("Passive Bonus");
private JLabel criticalStrikeLabelOne = new JLabel("Crit?");
private JLabel magicFormulaLabelOne = new JLabel("Spell Damage");
private JLabel magicFormulaLabelTwo = new JLabel("Intellect");
private JLabel magicFormulaLabelThree = new JLabel("Passive Bonus");
private JLabel magicFormulaLabelFour = new JLabel("Spell Power");
private JLabel magicFormulaLabelFive = new JLabel("Healing Power");
private JLabel attackFormulaOutputLabel = new JLabel("AF Output");
private JLabel defenceFormulaOutputLabel = new JLabel("DF Output");
private JLabel magicFormulaOutputLabel = new JLabel("MF Output");
private JLabel attackFormulaCategoryLabel = new JLabel("AF");
private JLabel defenceFormulaCategoryLabel = new JLabel("DF");
private JLabel magicFormulaCategoryLabel = new JLabel("MF");
private JTextArea magicFormulaSpellDamage = new JTextArea("", 1, 4); //String, Rows, Columns
private JTextArea magicFormulaIntellect = new JTextArea("", 1, 4);
private JTextArea magicFormulaPassiveBonus = new JTextArea("", 1, 4);
private JTextArea magicFormulaSpellPower = new JTextArea("", 1, 4);
private JTextArea magicFormulaHealingPower = new JTextArea("", 1, 4);
private JTextArea attackFormulaOutput = new JTextArea("", 1, 4); //String, Rows, Columns
private JTextArea defenceFormulaOutput = new JTextArea("", 1, 4);
private JTextArea magicFormulaOutput = new JTextArea("", 1, 4);
private JTextArea attackFormulaMainAttribute = new JTextArea("", 1, 4); //String, Rows, Columns
private JTextArea attackFormulaWeaponRoll = new JTextArea("", 1, 4);
private JTextArea attackFormulaPassiveBonus = new JTextArea("", 1, 4);
private JTextArea attackFormulaBaseDamage = new JTextArea("", 1, 4);
private JTextArea defenceFormulaConstitution = new JTextArea("", 1, 4); //String, Rows, Columns
private JTextArea defenceFormulaArmor = new JTextArea("", 1, 4);
private JTextArea defenceFormulaPassiveBonus = new JTextArea("", 1, 4);
private JRadioButton criticalStrikeTrue = new JRadioButton("True"); //Creates a radio button that says True beside it.
private JRadioButton criticalStrikeFalse = new JRadioButton("False"); //Creates a radio button that says False beside it.
private int tempInteger = 0;
public Interface()
{
setSize(640, 480); //Sets the size of the game window
setLocationRelativeTo(null); //Centers the window on the users screen.
setTitle("DnDFormulator"); //Sets the title of the game window
setDefaultCloseOperation(EXIT_ON_CLOSE); //Basically this makes it so when you hit the red X the window and program will close.
setResizable(false); //Makes it so that the user cannot resize the JFrame.
JPanel formulatorPanel = new JPanel(); //Creates a new JPanel to put everything on.
getContentPane().add(formulatorPanel);
formulatorPanel.setLayout(null); //Makes it so you can manually positon everything on the JPanel using XY coords.
ButtonGroup criticalButtonGroup = new ButtonGroup(); //Creates a group so that we can group together radio buttons.
criticalButtonGroup.add(criticalStrikeTrue); //Adds the criticalStrikeTrue radio button to be added to the criticalButtonGroup.
criticalButtonGroup.add(criticalStrikeFalse); //Adds the criticalStrikeFalse radio button to be added to the criticalButtonGroup.
criticalStrikeFalse.setSelected(true); //Sets the criticalStrikeFalse radio button to be selected automatically.
JButton calculateButton = new JButton("Calculate!");
formulatorPanel.add(calculateButton);
formulatorPanel.add(attackFormulaMainAttribute);
formulatorPanel.add(attackFormulaWeaponRoll);
formulatorPanel.add(attackFormulaPassiveBonus);
formulatorPanel.add(attackFormulaBaseDamage);
formulatorPanel.add(defenceFormulaConstitution);
formulatorPanel.add(defenceFormulaArmor);
formulatorPanel.add(defenceFormulaPassiveBonus);
formulatorPanel.add(criticalStrikeTrue);
formulatorPanel.add(criticalStrikeFalse);
formulatorPanel.add(magicFormulaSpellDamage);
formulatorPanel.add(magicFormulaIntellect);
formulatorPanel.add(magicFormulaPassiveBonus);
formulatorPanel.add(magicFormulaSpellPower);
formulatorPanel.add(magicFormulaHealingPower);
formulatorPanel.add(attackFormulaOutput);
formulatorPanel.add(defenceFormulaOutput);
formulatorPanel.add(magicFormulaOutput);
formulatorPanel.add(attackFormulaLabelOne);
formulatorPanel.add(attackFormulaLabelTwo);
formulatorPanel.add(attackFormulaLabelThree);
formulatorPanel.add(attackFormulaLabelFour);
formulatorPanel.add(defenceFormulaLabelOne);
formulatorPanel.add(defenceFormulaLabelTwo);
formulatorPanel.add(defenceFormulaLabelThree);
formulatorPanel.add(criticalStrikeLabelOne);
formulatorPanel.add(magicFormulaLabelOne);
formulatorPanel.add(magicFormulaLabelTwo);
formulatorPanel.add(magicFormulaLabelThree);
formulatorPanel.add(magicFormulaLabelFour);
formulatorPanel.add(magicFormulaLabelFive);
formulatorPanel.add(attackFormulaOutputLabel);
formulatorPanel.add(defenceFormulaOutputLabel);
formulatorPanel.add(magicFormulaOutputLabel);
formulatorPanel.add(attackFormulaCategoryLabel);
formulatorPanel.add(defenceFormulaCategoryLabel);
formulatorPanel.add(magicFormulaCategoryLabel);
attackFormulaMainAttribute.setBounds(50, 50, 50, 20);
attackFormulaWeaponRoll.setBounds(140, 50, 50, 20);
attackFormulaPassiveBonus.setBounds(230, 50, 50, 20);
attackFormulaBaseDamage.setBounds(320, 50, 50, 20);
defenceFormulaConstitution.setBounds(50, 90, 50, 20);
defenceFormulaArmor.setBounds(140, 90, 50, 20);
defenceFormulaPassiveBonus.setBounds(230, 90, 50, 20);
criticalStrikeTrue.setBounds(50, 120, 80, 20);
criticalStrikeFalse.setBounds(130, 120, 80, 20);
magicFormulaSpellDamage.setBounds(50, 160, 50, 20);
magicFormulaIntellect.setBounds(140, 160, 50, 20);
magicFormulaPassiveBonus.setBounds(230, 160, 50, 20);
magicFormulaSpellPower.setBounds(320, 160, 50, 20);
magicFormulaHealingPower.setBounds(410, 160, 50, 20);
attackFormulaOutput.setBounds(50, 250, 50, 20);
defenceFormulaOutput.setBounds(140, 250, 50, 20);
magicFormulaOutput.setBounds(230, 250, 50, 20);
attackFormulaOutput.setEditable(false); //Makes it so that the user cannot type in this JTextArea
defenceFormulaOutput.setEditable(false);
magicFormulaOutput.setEditable(false);
attackFormulaMainAttribute.setText("0");
attackFormulaWeaponRoll.setText("0");
attackFormulaPassiveBonus.setText("0");
attackFormulaBaseDamage.setText("0");
defenceFormulaConstitution.setText("0");
defenceFormulaArmor.setText("0");
defenceFormulaPassiveBonus.setText("0");
magicFormulaSpellDamage.setText("0");
magicFormulaIntellect.setText("0");
magicFormulaPassiveBonus.setText("0");
magicFormulaSpellPower.setText("0");
magicFormulaHealingPower.setText("0");
attackFormulaOutput.setText("0");
defenceFormulaOutput.setText("0");
magicFormulaOutput.setText("0");
attackFormulaLabelOne.setBounds(50, 30, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
attackFormulaLabelTwo.setBounds(140, 30, 100, 20);
attackFormulaLabelThree.setBounds(230, 30, 100, 20);
attackFormulaLabelFour.setBounds(320, 30, 100, 20);
defenceFormulaLabelOne.setBounds(50, 70, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaLabelTwo.setBounds(140, 70, 100, 20);
defenceFormulaLabelThree.setBounds(230, 70, 100, 20);
criticalStrikeLabelOne.setBounds(20, 120, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabelOne.setBounds(50, 140, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
magicFormulaLabelTwo.setBounds(140, 140, 100, 20);
magicFormulaLabelThree.setBounds(230, 140, 100, 20);
magicFormulaLabelFour.setBounds(320, 140, 100, 20);
magicFormulaLabelFive.setBounds(410, 140, 100, 20);
attackFormulaOutputLabel.setBounds(50, 230, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaOutputLabel.setBounds(140, 230, 100, 20);
magicFormulaOutputLabel.setBounds(230, 230, 100, 20);
attackFormulaCategoryLabel.setBounds(30, 50, 100, 20); //X position, Y Position, Length in pixels, Height in pixels.
defenceFormulaCategoryLabel.setBounds(30, 90, 100, 20);
magicFormulaCategoryLabel.setBounds(30, 160, 100, 20);
calculateButton.setBounds(50, 400, 100, 20);
calculateButton.setFocusPainted(false);
calculateButton.addActionListener(new ActionListener() { //Action listener for the calculateButton
public void actionPerformed(ActionEvent e) {
Formulator tempReference = new Formulator();
String attackFormulaStringOne = attackFormulaMainAttribute.getText();
String attackformulaStringTwo = attackFormulaWeaponRoll.getText();
String attackFormulaStringThree = attackFormulaPassiveBonus.getText();
String attackFormulaStringFour = attackFormulaBaseDamage.getText();
String defenceFormulaStringOne = defenceFormulaConstitution.getText();
String defenceFormulaStringTwo = defenceFormulaArmor.getText();
String defenceFormulaStringThree = defenceFormulaPassiveBonus.getText();
String magicFormulaStringOne = magicFormulaSpellDamage.getText();
String magicformulaStringTwo = magicFormulaIntellect.getText();
String magicFormulaStringThree = magicFormulaPassiveBonus.getText();
String magicFormulaStringFour = magicFormulaSpellPower.getText();
String magicFormulaStringFive = magicFormulaHealingPower.getText();
int attackFormulaTempIntOne = Integer.parseInt(attackFormulaStringOne);
int attackFormulaTempIntTwo = Integer.parseInt(attackFormulaStringTwo);
int attackFormulaTempIntThree = Integer.parseInt(attackFormulaStringThree);
int attackFormulaTempIntFour = Integer.parseInt(attackFormulaStringFour);
int defenceFormulaTempIntOne = Integer.parseInt(defenceFormulaStringOne);
int defenceFormulaTempIntTwo = Integer.parseInt(defenceFormulaStringTwo);
int defenceFormulaTempIntThree = Integer.parseInt(defenceFormulaStringThree);
int magicFormulaTempIntOne = Integer.parseInt(magicFormulaStringOne);
int magicFormulaTempIntTwo = Integer.parseInt(magicFormulaStringTwo);
int magicFormulaTempIntThree = Integer.parseInt(magicFormulaStringThree);
int magicFormulaTempIntFour = Integer.parseInt(magicFormulaStringFour);
int magicFormulaTempInt = Integer.parseInt(magicFormulaStringFive);
tempReference.formulaMainAttributeSetter(attackFormulaTempIntOne);
tempReference.formulaWeaponRollSetter(attackFormulaTempIntTwo);
tempReference.formulaPassiveBonusAttack(attackFormulaTempIntThree);
tempReference.formulaBaseDamageSetter(attackFormulaTempIntFour);
tempReference.formulaConstitutionSetter(defenceFormulaTempIntOne);
tempReference.formulaArmorSetter(defenceFormulaTempIntTwo);
tempReference.formulaPassiveBonusDefenceSetter(defenceFormulaTempIntThree);
tempReference.formulaSpellDamageSetter(magicFormulaTempIntOne);
tempReference.formulaIntellectSetter(magicFormulaTempIntTwo);
tempReference.formulaPassiveBonusmagicSetter(magicFormulaTempIntThree);
tempReference.formulaSpellPowerSetter(magicFormulaTempIntFour);
tempReference.formulaHealingPowerSetter(magicFormulaTempIntFive);
if (criticalStrikeTrue.isSelected() == true)
tempReference.formulaCriticalStrikeSetter(true);
else
tempReference.formulaCriticalStrikeSetter(false);
if ( (tempReference.formulaSpellPowerSetter = Integer.parseInt(magicFormulaStringFour) ) == 0 )
tempInteger = 0;
else
tempInteger = 1;
//Call the formulas here and infut test into the output
attackFormulaOutput.setText(""+tempReference.attackFormula()+"");
defenceFormulaOutput.setText(""+tempReference.defenceFormula()+"");
magicFormulaOutput.setText(""+tempReference.magicFormula(tempInteger)+"");
}});
setVisible(true); //Makes the JFrame, also known ass gameWindow visible to the user.
}
}