Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple Errors  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline tyeeeee1
« Posted 2012-12-29 00:36:20 »

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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
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.
   }
}


You can see the errors here:
http://i50.tinypic.com/faztsp.png
Offline LunaticEdit
« Reply #1 - Posted 2012-12-29 00:42:53 »

Check your capitalization. attackFormulaStringTwo does not exist, you called it attackformulaStringTwo. Same with the others Cheesy

Offline tyeeeee1
« Reply #2 - Posted 2012-12-29 00:45:46 »

Check your capitalization. attackFormulaStringTwo does not exist, you called it attackformulaStringTwo. Same with the others Cheesy

Bleh, thanks a ton. I totally forgot that the spell check in the program I'm using doesn't care about case...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GabrielBailey74
« Reply #3 - Posted 2012-12-29 01:03:38 »

Below are the things that:
A: Don't exist Yawn
B: Might be misspelled? / Don't exist? Shocked
1  
2  
3  
4  
5  
6  
magicFormulaTempIntFive /* Doesn't exist */
tempReference.formulaSpellPowerSetter /* Doesn't exist */
tempReference.formulaPassiveBonusmagicSetter /* M needs to be capitalized, it exists */
tempReference.formulaPassiveBonusAttack /* Doesn't exist, similar method name = formulaPassiveBonusAttackSetter */
magicFormulaStringTwo /* Actual variable name's 'F' needs to be capitalized, it exists */
attackFormulaStringTwo /* Actual variable name's 'F' needs to be capitalized, it exists */


All the errors actually fit into 1 Screen-Shot Cheesy


I'd recommend you download Eclipse IDE, or another IDE lol.
Just saying Roll Eyes

Offline tyeeeee1
« Reply #4 - Posted 2012-12-29 01:42:13 »

It's all fixed and working now. I usually notice my spelling errors, that's how I correct those errors usually; But every once in awhile I totally forget that the spell check in Notepad++ doesn't care about the case as long as the letters are correct. Thanks for the help.

(Yes, I know I shouldn't be using Notepad++)
Offline LunaticEdit
« Reply #5 - Posted 2012-12-29 01:43:55 »

It's all fixed and working now. I usually notice my spelling errors, that's how I correct those errors usually; But every once in awhile I totally forget that the spell check in Notepad++ doesn't care about the case as long as the letters are correct. Thanks for the help.

(Yes, I know I shouldn't be using Notepad++)

Why do you punish yourself like that  Undecided

Offline tyeeeee1
« Reply #6 - Posted 2012-12-29 01:48:05 »

Why do you punish yourself like that  Undecided

I'm really used to Notepad++ and I find eclipse and netbeans a bit of a pain to get started with since I'd need to devote a few hours to figure them out and learn how packages and that work. Notepad++ just easier, although slightly confusing with 1000 lines of code and multiple classes, to work with for me atm.  Wink
Offline actual

JGO Coder


Medals: 23



« Reply #7 - Posted 2012-12-29 01:56:56 »

I haven't done much (any really) swing programming but the amount of variables here is insane. I have some comments below that IMHO will make things somewhat easier.

One thing is that it appears that all of your attributes have either the word Formula or Output in them, with most having Formula. Given that your class is called Formulator, I think you could omit Formula from all of the variable names as it is implied. This will give you  fewer places for typos to hit you and will save you some horizontal screen space.

In java, for setters, setXYZ is more common than XYZsetter so your formulaPassiveBonusAttackSetter(45) would become setPassiveBonusAttack(45) (assuming you also remove "Formula" from the name as I suggested.

Probably not the best idea to name a class "Interface". I know it doesn't hurt anything but personally I would try to avoid names that are java keywords with different capitalization.


I find your JLabel variables hard to decipher (I have to look at the text set in constructor) and probably makes it easier to make subtle mistakes. For instance, I would change magicFormulaLabelThree to magicPassiveBonusLabel. In general, with this many variables related variables, you need to make things as consistent as possible, such as magicFormulaSpellDamageLabel, magicFormulaSpellDamageTextArea

The comments on your list of private variables are confusing. At first I thought it was indicating that the field was a subtraction between two fields. Your comments contain two parts, a restatement of the variable name and the "Type" of attribute it is. The first part is redundant (it doesn't give us any additional information) and the format obscures the second part. You could convert it to something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
// Attack Formula attributes
private int formulaMainAttribute = 0;
private int formulaWeaponRoll= 0;
private int formulaPassiveBonusAttack = 0;
private int formulaBaseDamage = 0;

// Defense Formula attributes
private int formulaConstitution = 0;
private int formulaArmor = 0;
private int formulaPassiveBonusDefence = 0;

// Magic formula attributes
private int formulaSpellDamage = 0;
private int formulaIntellect = 0;
private int formulaPassiveBonusMagic = 0;
private int formulaSpellPower = 0;
private int formulaHealingPower = 0;

// Formula outputs
private double outputAttackFormula = 0.0;
private double outputDefenceFormula= 0.0;
private double outputMagicFormula = 0.0;

// Did you crit?
private boolean formulaCriticalStrike = false;



What I think might be a bigger help is to look at your interface and realize that you are grouping things together by their variable name, when maybe putting them in a class might work better.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public class GUIElement {

   private JLabel label;
   private JTextArea textArea;

   public GUIElement(String labelText, String taText, int taRow, int taColumn) {
        label = new JLabel(labelText);
        textArea = new JTextArea(taText,taRow,taColumn);
   }

   public JLabel getLabel() {
      return label;
   }

  public JTextArea getTextArea() {
      return textArea;
   }

   public void setTextAreaBounds(int a, int , int c, int d) {
      textArea.setBounds(a,b,c,d);
   }
}


Now you can set up your elements like:
1  
2  
3  
4  
GUIElement attackWeaponRoll = new GUIElement("Attack Weapon Roll","",1,4);

// Add the element to the window
formulatorPanel.add(attackWeaponRoll.getTextArea());


and now you know your elements are named consistently. You could then even turn your elements in an array to simplify how you call them:
1  
2  
3  
4  
// Add all of the text areas
for (int i=0; i<guiElements.length; i++) {
   formulatorPanel.add(guiElements[i].getTextArea();
}

 
Not only is it a whole lot shorter, it also means if you add a new attribute to the array (or remove one) the loop will still work fine.


Offline tyeeeee1
« Reply #8 - Posted 2012-12-29 02:03:07 »

I never thought twice about the names since I usually know what's what and what it does, thanks for the tips/information though they should prove to be useful in a little bit.  Grin
Offline actual

JGO Coder


Medals: 23



« Reply #9 - Posted 2012-12-29 02:14:44 »

I never thought twice about the names since I usually know what's what and what it does, thanks for the tips/information though they should prove to be useful in a little bit.  Grin

And yet had to ask for help on a forum for what turned out to be a simple spelling mistake that an IDE would have pointed out right after you typed it. It's not that we all don't make silly mistakes from time to time (I do often enough) but it is going to take you soooo much longer to write, update, or debug code like this. It's ok not to go the IDE route, but it means you have to take on more yourself, and there is a limit to what anyone can hold in their head at one time. Naming consistency and using better abstractions becomes critical.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tyeeeee1
« Reply #10 - Posted 2012-12-29 02:16:07 »

And yet had to ask for help on a forum for what turned out to be a simple spelling mistake that an IDE would have pointed out right after you typed it. It's not that we all don't make silly mistakes from time to time (I do often enough) but it is going to take you soooo much longer to write, update, or debug code like this. It's ok not to go the IDE route, but it means you have to take on more yourself, and there is a limit to what anyone can hold in their head at one time. Naming consistency and using better abstractions becomes critical.

I'll have to keep that in mind then, time to go re-write the program!  Cheesy
Offline ReBirth
« Reply #11 - Posted 2012-12-29 04:49:24 »

My little tips on variable names,

- You have same "formula" word as prefix. It wont be useful when you use Eclipse auto-complete (CTRL SPACE). Put it as suffix and short it like attackFrml if needed.
- "Attack", "Defense", etc are pretty common in our mind. You can use "ATK", "DEF" which shorter and still meaningful.
- Max 2 capital letters on it.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!