After all this time OOP just clicked, I am laughing at myself like a mad scientist. I just needed a project to really required it I suppose. Reading about design patterns was a really cool moment for me. However I have questions:
I have a abstract class like this below:
public abstract class Weapon { protected String name; protected int zeroRoundCount; protected int qualRoundCount; protected int practiceRoundCount; JFrame frame; JButton enterBtn; JButton closeBtn; JLabel zeroLbl; JLabel practiceLbl; JLabel qualLbl; JLabel calulateLbl; JTextField zeroTextBox; JTextField practiceTextBox; JTextField qualTextBox; JTextField calculateTxtBox; Weapon(String name) { zeroRoundCount=18; qualRoundCount=40; practiceRoundCount=60; String weaponName = null; frame = new JFrame(weaponName); frame.getContentPane().setLayout(new GridLayout(0,1)); frame.setSize(240,220); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //button will calculate total rounds needed enterBtn = new JButton("Enter"); closeBtn = new JButton("Close"); //text box's will be default values from abstract Weapon zeroTextBox= new JTextField(5); practiceTextBox= new JTextField(5); qualTextBox= new JTextField(5); calculateTxtBox= new JTextField(10); //creating labels zeroLbl= new JLabel("Zero"); practiceLbl= new JLabel("Practice");; qualLbl= new JLabel("Qual"); calulateLbl = new JLabel("Total Ammo Needed"); frame.add(zeroLbl); frame.add(zeroTextBox); frame.add(qualLbl); frame.add(qualTextBox); frame.add(practiceLbl); frame.add(practiceTextBox); frame.add(calulateLbl); frame.add(calculateTxtBox); frame.add(enterBtn); frame.add(closeBtn); frame.setVisible(true); } }
I make another class:
package army.strac; public class M4 extends Weapon{ M4() { super("M4"); } }
Then a main class and it runs. Now how can I put the actionListners methods:
//example zeroTextBox.addActionListener(new ActionListener) { public void actionPerformed(ActionEvent ae) { zeroTextBox.setText(zeroRoundCount); } }
I want to put them in the abstract class set them all up and simply change the field numbers values in the subclass. Therefore for every weapon type I just change the number required by accesses the field numbers in the constructor and BAM I am done.