8 Replies - 561 Views - Last Post: 09 August 2012 - 08:51 PM Rate Topic: -----

#1 slacman69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-July 12

Array not filling

Posted 09 August 2012 - 05:32 PM

Can't get my Arrays to fill so they display in my comboboxes. I have tried placing the for statements in multiple areas and cannot get it to work. I would also like to know if I need to include any error catching statements in my program. I know the text fields may need to have an error catch but not sure if it's necessary.

Was also wondering if the text area displayed by my calculate box would appear in a new window or if it needs to be assigned a position in the frame. I'm hoping I got this correct so I can continue my work on this project.

package shipbuilder;//Main Program
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;

public class Shipbuilder{

        //create arrays
        String[] atkname = {"Auto Cannon", "Heavy Auto Cannon", "Light Mass Driver", "Mass Driver", "Heavy Mass Driver", "Light Laser Cannon", "Laser Cannon", "Heavy Laser Cannon", 
                            "Light Ion Cannon", "Ion Cannon", "Heavy Ion Cannon", "Light Plasma Cannon", "Plasma Cannon", "Heavy Plasma Cannon", "Light Phase Cannon", "Phase Cannon", "Heavy Phase Cannon",
                            "Light Graviton Shearer", "Graviton Shearer", "Heavy Graviton Shearer", "Light Disruptor Cannon", "Disruptor Cannon", "Heavy Disruptor Cannon", "Light Quantum Devastator",
                            "Quantum Devastator", "Heavy Quantum Devastator", "Light Singularity Cannon", "Singularity Cannon", "Heavy Singularity Cannon", "Light Antiproton Cannon", "Antiproton Cannon", 
                            "Heavy Antiproton Cannon", "Light Null Ray", "Null Ray", "Heavy Null Ray", "Light Thetacron Cannon", "Thetacron Cannon", "Heavy Thetacron Cannon", "Light Quasi-Chaotic Blaster",
                            "Quasi-Chaotic Blaster", "Heavy Quasi-Chaotic Blaster"};
        String[] thrustname = {"Maneuvering Thrusters", "Maneuvering Thrusters Mark II", "Maneuvering Thrusters Mark III", "Spacial Thrusters", "Spacial Thrusters Mark II", "Spacial Thrusters Mark III", 
                               "Microwarp Nacelle", "Microwarp Nacelle Mark II", "Microwarp Nacelle Mark III", "Quantum Overlay Engine", "Quantum Overlay Engine Mark II", "Quantum Overlay Engine Mark III", 
                               "Trans-Temporal Nacelle", "Trans-Temporal Nacelle Mark II", "Trans-Temporal Nacelle Mark III", "Trans-Entropy Drive", "Trans-Entropy Drive Mark II", "Trans-Entropy Drive Mark III"};
        String[] dampname = {"Autopilot Console", "Autopilot Console Mark II", "Motion Compensator", "Motion Compensator Mark II", "Motion Compensator Mark III", 
                             "Inertial Dampeners", "Inertial Dampeners Mark II", "Inertial Dampeners Mark III", "Inertial Canceler", "Inertial Canceler Mark II", "Inertial Canceler Mark III", 
                             "Phase Shift Engine", "Phase Shift Engine Mark II", "Phase Shift Engine Mark III", "Energy Nullifier", "Energy Nullifier Mark II", "Energy Nullifier Mark III", 
                             "Exergonic Inverter", "Exergonic Inverter Mark II", "Exergonic Inverte Mark IIIr"};
        String[] hullname = {"Titanium Plating", "Reinforced Titanium Plating", "Hardened Titanium Plating", "Whipple Plating", "Hardened Whipple Plating", "Ablative Whipple Plating", 
                             "Durtanium Plating", "Reinforced Durtanium Plating", "Hardened Durtanium Plating", "Microgel Armor", "Compressed Microgel Armor", "Merged Microgel Armor", 
                             "Nanosphere Plating", "Compressed Nanosphere Plating", "Merged Nanosphere Plating", "Q-Phased Plating", "Reactive Q-Phased Plating", "Overcharge Q-Phased Plating", 
                             "Nexus Armor", "Compressed Nexus Armor", "Merged Nexus Armor", "Neutronium Armor", "Core Neutronium Armor", "Deep Core Neutronium Armor", 
                             "Fermionic Armor", "Stabilized Fermionic Armor", "Perfect Fermionic Armor", "Syncopated Plating", "Stabilized Syncopated Plating", "Perfect Syncopated Plating"};
        String[] reactorname = {"Fusion Reactor", "Fusion Reactor Mark II", "Fusion Reactor Mark III", "Fusion Reactor Mark IV", 
                                "Graviton Core", "Graviton Core Mark II", "Graviton Core Mark III", "Graviton Core Mark IV", 
                                "Quantum Capacitor", "Quantum Capacitor Mark II", "Quantum Capacitor Mark III", "Quantum Capacitor Mark IV", 
                                "Antimatter Reactor", "Antimatter Reactor Mark II", "Antimatter Reactor Mark III", "Antimatter Reactor Mark IV", 
                                "Singularity Core", "Singularity Core Mark II", "Singularity Core Mark III", "Singularity Core Mark IV", 
                                "Zero-Point Reactor", "Zero-Point Reactor Mark II", "Zero-Point Reactor Mark III", "Zero-Point Reactor Mark IV", 
                                "Dark Energy Core", "Dark Energy Core Mark II", "Dark Energy Core Mark III", "Dark Energy Core Mark IV", 
                                "Intra-D Collider", "Intra-D Collider Mark II", "Intra-D Collider Mark III", "Intra-D Collider Mark IV", 
                                "Supernova Generator", "Supernova Generator Mark II", "Supernova Generator Mark III", "Supernova Generator Mark IV", 
                                "Proxy-Universe Reactor", "Proxy-Universe Reactor Mark II", "Proxy-Universe Reactor Mark III", "Proxy-Universe Reactor Mark IV"};
        String[] scanname = {"Proximity Sensor", "Proximity Sensor Mark II", "EM Scanner", "EM Scanner Mark II", "EM Scanner Mark III", "Wideband Scanner", "Wideband Scanner Mark II", "Wideband Scanner Mark III", 
                             "Multiwave Sensor", "Multiwave Sensor Mark II", "Multiwave Sensor Mark III", "Subspace Sensor", "Subspace Sensor Mark II", "Subspace Sensor Mark III", "Quantum Resonance Sensor", "Quantum Resonance Sensor Mark II",
                             "Quantum Resonance Sensor Mark III", "Sub-Dimensional Sensor", "Sub-Dimensional Sensor Mark II", "Sub-Dimensional Sensor Mark III", "Tachyon Sensor", "Tachyon Sensor Mark II", "Tachyon Sensor Mark III",
                             "X-Manifold Detector", "X-Manifold Detector Mark II", "X-Manifold Detector Mark III", "Hyperflux Sensor", "Hyperflux Sensor Mark II", "Hyperflux Sensor Mark III", "Continuum Analyzer", "Continuum Analyzer Mark II",
                             "Continuum Analyzer Mark III"};
        String[] cloakname = {"EM Absorbant Panels", "EM Absorbant Panels Mark II", "EM Absorbant Panels Mark III", "Refraction Panels Mark II", "Refraction Panels Mark III", "EM Adaptive Panels",
                              "EM Adaptive Panels Mark II", "EM Adaptive Panels Mark III", "Stealth Field Emitter", "Stealth Field Emitter Mark II", "Stealth Field Emitter Mark III", "Cloak Field Generator",
                              "Cloak Field Generator Mark II", "Cloak Field Generator Mark III", "Dimensional Masking", "Dimensional Masking Mark II", "Dimensional Masking Mark III"};
        String[] jamname = {"Proximity Jammer", "Proximity Jammer Mark II", "Sensor Jammer", "Sensor Jammer Mark II", "Sensor Jammer Mark III", "Wideband Jammer", "Wideband Jammer Mark II", 
                            "Wideband Jammer Mark III", "Quantum Jammer", "Quantum Jammer Mark II", "Quantum Mark III", "Subspace Jammer", "Subspace Jammer Mark II", "Subspace Jammer Mark III", 
                            "Anti-Tachyon Jammer", "Anti-Tachyon Jammer Mark II", "Anti-Tachyon Jammer Mark III", "Inverse Flux Jammer", "Inverse Flux Jammer Mark II", "Inverse Flux Jammer Mark III"};
        
        int[] atkrating = {1,2,3,5,7,12,15,18,25,29,33,42,47,52,63,69,75,88,95,
                          102,117,125,133,150,159,168,187,197,207,228,239,250,
                          274,287,300,328,343,358,391,409,427};
        int[] thrustrating = {6,10,14,84,94,104,176,190,204,300,318,336,456,478,500,720,770,820};
        int[] damprating = {1,2,24,30,36,50,58,6,126,138,150,234,250,266,374,394,414,552,590,626};
        int[] hullrating = {20,25,30,45,55,65,90,105,120,155,175,195,240,265,290,345,375,405,470,
                           505,540,615,644,695,785,835,885,985,1045,1105};
        int[] reactorrating = {10,13,16,19,23,27,31,35,40,45,50,55,62,69,76,83,93,103,113,123,136,149,
                              162,175,191,207,223,239,258,277,296,315,337,359,381,403,442,470,500,540};
        int[] scanrating = {4,9,20,26,32,46,53,62,80,90,100,124,138,152,186,206,226,272,298,324,382,414,
                           446,516,554,592,670,712,756,836,895,960};
        int[] cloakrating = {10,13,16,40,45,50,93,103,113,191,207,223,337,359,381,553,587,621};
        int[] jamrating = {3,5,23,27,31,62,69,76,136,149,162,258,277,296,435,463,491,691,726,761};
        
        int[] atksize = {3,4,5,6,7,9,10,11,13,14,15,17,18,19,21,22,23,25,26,27,
                        29,30,31,33,34,35,37,38,39,41,42,43,45,46,47,49,50,51,53,54,55};
        int[] thrustsize = {10,12,14,34,36,38,50,52,54,66,68,70,82,84,86,98,100,102};
        int[] dampsize = {3,5,18,20,22,26,28,30,42,44,46,58,60,62,74,76,78,90,92,94};
        int[] hullsize = {5,6,7,9,10,11,13,14,15,17,18,19,21,22,23,25,26,27,29,30,31,33,34,35,37,38,39,41,42,43};
        int[] reactorsize = {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};
        int[] scansize = {5,10,20,22,24,28,30,32,36,38,40,44,46,48,52,54,56,60,62,64,68,70,72,76,78,80,84,86,88,92,94,96};
        int[] cloaksize = {10,11,12,18,19,20,26,27,28,34,35,36,42,43,44,50,51,52};
        int[] jamsize = {4,6,14,15,16,22,23,24,30,31,32,38,39,40,46,47,48,54,55,56};
	
        private attackModule[] attack = new attackModule[atkname.length];
	private defenseModule[] thrusters = new defenseModule[thrustname.length];
	private defenseModule[] dampeners = new defenseModule[dampname.length];
	private armorModule[] armor = new armorModule[hullname.length];
	private reactorModule[] reactor = new reactorModule[reactorname.length];
	private scanModule[] scanner = new scanModule[scanname.length];
	private cloakModule[] cloaking = new cloakModule[cloakname.length];
	private cloakModule[] jammer = new cloakModule[jamname.length];
        
        
        
        // create fields for data
        private JFormattedTextField atkfield;
        private JFormattedTextField thrustfield;
        private JFormattedTextField dampfield;
        private JFormattedTextField hullfield;
        private JFormattedTextField reactorfield;
        private JFormattedTextField scanfield;
        private JFormattedTextField cloakfield;
        private JFormattedTextField jamfield;
        JTextArea results;
        
        //values for fields
        private int atk = 0;
        private int thrust = 0;
        private int damp = 0;
        private int hull = 0;
        private int react = 0;
        private int scan = 0;
        private int cloak = 0;
        private int jam = 0;
        
        //labels for fields
        private JLabel atkLabel;
        private JLabel thrustLabel;
        private JLabel dampLabel;
        private JLabel hullLabel;
        private JLabel reactLabel;
        private JLabel scanLabel;
        private JLabel cloakLabel;
        private JLabel jamLabel;
        
        //Strings for labels
        private static String atkString = "Attack Modules: Max 8";
        private static String thrustString = "Thruster Modules: Max 4";
        private static String dampString = "Dampener Modules: Max 4";
        private static String hullString = "Armor Modules: Max 5";
        private static String reactString = "Reactor Modules: Max 3";
        private static String scanString = "Scanner Modules: Max 5";
        private static String cloakString = "Cloaking Modules: Max 2";
        private static String jamString = "Jammer Modules: Max 2";
        
        //format and parse numbers
        private NumberFormat atkFormat;
        private NumberFormat thrustFormat;
        private NumberFormat dampFormat;
        private NumberFormat hullFormat;
        private NumberFormat reactFormat;
        private NumberFormat scanFormat;
        private NumberFormat cloakFormat;
        private NumberFormat jamFormat;
        
        //create buttons
        private JComboBox atkbox = new JComboBox(attack);
        private JComboBox thrustbox = new JComboBox(thrusters);
        private JComboBox dampbox = new JComboBox(dampeners);
        private JComboBox hullbox = new JComboBox(armor);
        private JComboBox reactorbox = new JComboBox(reactor);            
        private JComboBox scanbox = new JComboBox(scanner);            
        private JComboBox cloakerbox = new JComboBox(cloaking);            
        private JComboBox jambox = new JComboBox(jammer);            
        private JButton calculate = new JButton("Calculate");

	public class GridBagFrame extends JFrame{
        private GridBagLayout layout;
        private GridBagConstraints constraints;
        

        public GridBagFrame(){
            super("Ship Builder");
            layout = new GridBagLayout();
            setLayout(layout);
            constraints = new GridBagConstraints();
            setUpFormats();
            
            for (int i = 0; i < attack.length; i++) {
                attack[i] = new attackModule(atkname[i],atksize[i],atkrating[i]);
            }
            for (int i = 0; i < thrusters.length; i++) {
                thrusters[i] = new defenseModule(thrustname[i],thrustsize[i],thrustrating[i]);
            }
            for (int i = 0; i < dampeners.length; i++) {
                dampeners[i] = new defenseModule(dampname[i],dampsize[i],damprating[i]);
            }
            for (int i = 0; i < armor.length; i++) {
                armor[i] = new armorModule(hullname[i],hullsize[i],hullrating[i]);
            }
            for (int i = 0; i < reactor.length; i++) {
                reactor[i] = new reactorModule(reactorname[i],reactorsize[i],reactorrating[i]);
            }
            for (int i = 0; i < scanner.length; i++) {
                scanner[i] = new scanModule(scanname[i],scansize[i],scanrating[i]);
            }
            for (int i = 0; i < cloaking.length; i++) {
                cloaking[i] = new cloakModule(cloakname[i],cloaksize[i],cloakrating[i]);
            }
            for (int i = 0; i < jammer.length; i++) {
                jammer[i] = new cloakModule(jamname[i],jamsize[i],jamrating[i]);
            }
            //create labels
            atkLabel = new JLabel(atkString);
            thrustLabel = new JLabel(thrustString);
            dampLabel = new JLabel(dampString);
            hullLabel = new JLabel(hullString);
            reactLabel = new JLabel(reactString);
            scanLabel = new JLabel(scanString);
            cloakLabel = new JLabel(cloakString);
            jamLabel = new JLabel(jamString);
            
            //create text fields and set them up
            atkfield = new JFormattedTextField(atkFormat);
            atkfield.setValue(new Integer(atk));
            atkfield.setColumns(2);
            
            
            thrustfield = new JFormattedTextField(thrustFormat);
            thrustfield.setValue(new Integer(thrust));
            thrustfield.setColumns(2);
            
            
            dampfield = new JFormattedTextField(dampFormat);
            dampfield.setValue(new Integer(damp));
            dampfield.setColumns(2);
            
            
            hullfield = new JFormattedTextField(hullFormat);
            hullfield.setValue(new Integer(hull));
            hullfield.setColumns(2);
            
            
            reactorfield = new JFormattedTextField(reactFormat);
            reactorfield.setValue(new Integer(react));
            reactorfield.setColumns(2);
            
            
            scanfield = new JFormattedTextField(scanFormat);
            scanfield.setValue(new Integer(scan));
            scanfield.setColumns(2);
            
            
            cloakfield = new JFormattedTextField(cloakFormat);
            cloakfield.setValue(new Integer(cloak));
            cloakfield.setColumns(2);
            
            
            jamfield = new JFormattedTextField(jamFormat);
            jamfield.setValue(new Integer(jam));
            jamfield.setColumns(2);
            

            
            
            //add components
            addComponent(atkLabel,0,5,1,1);
            addComponent(atkbox, 1,1,3,1);
            addComponent(atkfield, 1,5,1,1);
            
            addComponent(thrustLabel,3,5,1,1);
            addComponent(thrustbox,4,1,3,1);
            addComponent(thrustfield, 4,5,1,1);
            
            addComponent(dampLabel,6,5,1,1);
            addComponent(dampbox,7,1,3,1);
            addComponent(dampfield, 7,5,1,1);
            
            addComponent(hullLabel,9,5,1,1);
            addComponent(hullbox,10,1,3,1);
            addComponent(hullfield, 10,5,1,1);
            
            addComponent(reactLabel,12,5,1,1);
            addComponent(reactorbox,13,1,3,1);
            addComponent(reactorfield, 13,5,1,1);
            
            addComponent(scanLabel,15,5,1,1);
            addComponent(scanbox,16,1,3,1);
            addComponent(scanfield, 16,5,1,1);
            
            addComponent(cloakLabel,18,5,1,1);
            addComponent(cloakerbox,19,1,3,1);
            addComponent(cloakfield, 19,5,1,1);
            
            addComponent(jamLabel,21,5,1,1);
            addComponent(jambox,22,1,3,1);
            addComponent(jamfield, 22,5,1,1);
            
            //tell accessibility tools about label/textfield pairs
            atkLabel.setLabelFor(atkfield);
            thrustLabel.setLabelFor(thrustfield);
            dampLabel.setLabelFor(dampfield);
            hullLabel.setLabelFor(hullfield);
            reactLabel.setLabelFor(reactorfield);
            scanLabel.setLabelFor(scanfield);
            cloakLabel.setLabelFor(cloakfield);
            jamLabel.setLabelFor(jamfield);
            
            constraints.weightx = 0;
            constraints.weighty = 0;
            constraints.fill = GridBagConstraints.NONE;
            addComponent(calculate,24,5,1,1);
            calculate.addActionListener(new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent a){
                    //retrieve size and rating from each combo box;
                    attackModule getAtk = (attackModule)atkbox.getSelectedItem();
                    int atkMsize = getAtk.getSize();
                    int atkMrate = getAtk.getRating();
                    defenseModule getThrust = (defenseModule)thrustbox.getSelectedItem();
                    int thrustMsize = getThrust.getSize();
                    int thrustMrate = getThrust.getRating();
                    defenseModule getDamp = (defenseModule)dampbox.getSelectedItem();
                    int dampMsize = getDamp.getSize();
                    int dampMrate = getDamp.getRating();
                    armorModule getHull = (armorModule)hullbox.getSelectedItem();
                    int hullMsize = getHull.getSize();
                    int hullMrate = getHull.getRating();
                    reactorModule getReactor = (reactorModule)reactorbox.getSelectedItem();
                    int reactMsize = getReactor.getSize();
                    int reactMrate = getReactor.getRating();
                    scanModule getScanner = (scanModule)scanbox.getSelectedItem();
                    int scanMsize = getScanner.getSize();
                    int scanMrate = getScanner.getRating();
                    cloakModule getCloaker = (cloakModule)cloakerbox.getSelectedItem();
                    int cloakMsize = getCloaker.getSize();
                    int cloakMrate = getCloaker.getRating();
                    cloakModule getJammer = (cloakModule)jambox.getSelectedItem();
                    int jamMsize = getJammer.getSize();
                    int jamMrate = getJammer.getRating();
            
                    //calculate total size and rating for each module and calculate total decks used
                    int atkTsize = atkMsize * Integer.parseInt(atkfield.getText());
                    int thrustTsize = thrustMsize * Integer.parseInt(thrustfield.getText());
                    int dampTsize = dampMsize * Integer.parseInt(dampfield.getText());
                    int hullTsize = hullMsize * Integer.parseInt(hullfield.getText());
                    int reactTsize = reactMsize * Integer.parseInt(reactorfield.getText());
                    int scanTsize = scanMsize * Integer.parseInt(scanfield.getText());
                    int cloakTsize = cloakMsize * Integer.parseInt(cloakfield.getText());
                    int jamTsize = jamMsize * Integer.parseInt(jamfield.getText());
            
                    int decksUsed = atkTsize + thrustTsize + dampTsize + hullTsize + reactTsize + 
                            scanTsize + cloakTsize + jamTsize;
            
                    int atkTrate = atkMrate * Integer.parseInt(atkfield.getText());
                    int thrustTrate = thrustMrate * Integer.parseInt(thrustfield.getText());
                    int dampTrate = dampMrate * Integer.parseInt(dampfield.getText());
                    int hullTrate = hullMrate * Integer.parseInt(hullfield.getText());
                    int reactTrate = reactMrate * Integer.parseInt(reactorfield.getText());
                    int scanTrate = scanMrate * Integer.parseInt(scanfield.getText());
                    int cloakTrate = cloakMrate * Integer.parseInt(cloakfield.getText());
                    int jamTrate = jamMrate * Integer.parseInt(jamfield.getText());  
                    int defTrate = thrustTrate + dampTrate;                         //calculate total defense
                    int cloakingTrate = cloakTrate + jamTrate;                      //calculate total cloak
                    results = new JTextArea("Decks Used: " + decksUsed + "\n" + "Attack Rating: " + atkTrate + "\n"
                            + "Defense Rating: " + defTrate + "\n" + "Total Hull: " + hullTrate + "\n" +
                            "Total Energy: " + reactTrate + "\n" + "Total Scan: " + scanTrate + "\n" +
                            "Total Cloak: " + cloakingTrate);
                }
            });
        }

        private void addComponent(Component component, int row, int column, int width, int height){
            constraints.gridx = column;
            constraints.gridy = row;
            constraints.gridwidth = width;
            constraints.gridheight = height;
            layout.setConstraints(component, constraints);
            add(component);
        }
    }

        private void setUpFormats(){
            atkFormat = NumberFormat.getNumberInstance();
            thrustFormat = NumberFormat.getNumberInstance();
            dampFormat = NumberFormat.getNumberInstance();
            hullFormat = NumberFormat.getNumberInstance();
            scanFormat = NumberFormat.getNumberInstance();
            reactFormat = NumberFormat.getNumberInstance();
            cloakFormat = NumberFormat.getNumberInstance();
            jamFormat = NumberFormat.getNumberInstance();
        }

	public static void main(String args[]){
            
            Shipbuilder b = new Shipbuilder();
            GridBagFrame gridBagFrame = b.new GridBagFrame();
            gridBagFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gridBagFrame.setSize(500, 500);
            gridBagFrame.setVisible(true);
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Array not filling

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Array not filling

Posted 09 August 2012 - 06:10 PM

Quote

Can't get my Arrays to fill so they display in my comboboxes.


Well, based on the various intializer lists you have, you're arrays are filled. Why your combo boxes aren't behaving correctly is a different story. But it would certainly help if you included the full code, so we can take a look your app, instead of diving deep into your code, which is not so fun.

1. Post code that compiles.
2. If possible, chop it down to the problematic areas. Remove the stuff that's not relevant to the problem.

Your code looks pretty complicated, so it would be better to chop it down.

This post has been edited by blackcompe: 09 August 2012 - 06:11 PM

Was This Post Helpful? 0
  • +
  • -

#3 slacman69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-July 12

Re: Array not filling

Posted 09 August 2012 - 07:47 PM

Here is my code. It is revised from my previous code as I realized that all my arrays were the same type so I only needed one class for them. This should compile correctly as it compiles for me. I am using netbeans to create this program.


package shipbuilder;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Justin
 */
public class Module {
    
	protected String name;
	protected int rating;
	protected int size;

	public Module(String name, int rating, int size){
		setName(name);
		setRating(rating);
		setSize(size);
	}

	public String getName(){
		return this.name;
	}

	public void setName(String moduleName){
		this.name = moduleName;
	}

	public int getRating(){
		return this.rating;
	}

	public void setRating(int moduleRating){
		this.rating = moduleRating;
	}

	public int getSize(){
		return this.size;
	}
	public void setSize(int moduleSize){
		this.size = moduleSize;
	}

    @Override
	public String toString(){
		return name + "   Rating:  " + rating + "   Size:  " + size;
	}
}


package shipbuilder;//Main Program
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;

public class Shipbuilder{

        //create arrays
        String[] atkname = {"Auto Cannon", "Heavy Auto Cannon", "Light Mass Driver", "Mass Driver", "Heavy Mass Driver", "Light Laser Cannon", "Laser Cannon", "Heavy Laser Cannon", 
                            "Light Ion Cannon", "Ion Cannon", "Heavy Ion Cannon", "Light Plasma Cannon", "Plasma Cannon", "Heavy Plasma Cannon", "Light Phase Cannon", "Phase Cannon", "Heavy Phase Cannon",
                            "Light Graviton Shearer", "Graviton Shearer", "Heavy Graviton Shearer", "Light Disruptor Cannon", "Disruptor Cannon", "Heavy Disruptor Cannon", "Light Quantum Devastator",
                            "Quantum Devastator", "Heavy Quantum Devastator", "Light Singularity Cannon", "Singularity Cannon", "Heavy Singularity Cannon", "Light Antiproton Cannon", "Antiproton Cannon", 
                            "Heavy Antiproton Cannon", "Light Null Ray", "Null Ray", "Heavy Null Ray", "Light Thetacron Cannon", "Thetacron Cannon", "Heavy Thetacron Cannon", "Light Quasi-Chaotic Blaster",
                            "Quasi-Chaotic Blaster", "Heavy Quasi-Chaotic Blaster"};
        String[] thrustname = {"Maneuvering Thrusters", "Maneuvering Thrusters Mark II", "Maneuvering Thrusters Mark III", "Spacial Thrusters", "Spacial Thrusters Mark II", "Spacial Thrusters Mark III", 
                               "Microwarp Nacelle", "Microwarp Nacelle Mark II", "Microwarp Nacelle Mark III", "Quantum Overlay Engine", "Quantum Overlay Engine Mark II", "Quantum Overlay Engine Mark III", 
                               "Trans-Temporal Nacelle", "Trans-Temporal Nacelle Mark II", "Trans-Temporal Nacelle Mark III", "Trans-Entropy Drive", "Trans-Entropy Drive Mark II", "Trans-Entropy Drive Mark III"};
        String[] dampname = {"Autopilot Console", "Autopilot Console Mark II", "Motion Compensator", "Motion Compensator Mark II", "Motion Compensator Mark III", 
                             "Inertial Dampeners", "Inertial Dampeners Mark II", "Inertial Dampeners Mark III", "Inertial Canceler", "Inertial Canceler Mark II", "Inertial Canceler Mark III", 
                             "Phase Shift Engine", "Phase Shift Engine Mark II", "Phase Shift Engine Mark III", "Energy Nullifier", "Energy Nullifier Mark II", "Energy Nullifier Mark III", 
                             "Exergonic Inverter", "Exergonic Inverter Mark II", "Exergonic Inverte Mark IIIr"};
        String[] hullname = {"Titanium Plating", "Reinforced Titanium Plating", "Hardened Titanium Plating", "Whipple Plating", "Hardened Whipple Plating", "Ablative Whipple Plating", 
                             "Durtanium Plating", "Reinforced Durtanium Plating", "Hardened Durtanium Plating", "Microgel Armor", "Compressed Microgel Armor", "Merged Microgel Armor", 
                             "Nanosphere Plating", "Compressed Nanosphere Plating", "Merged Nanosphere Plating", "Q-Phased Plating", "Reactive Q-Phased Plating", "Overcharge Q-Phased Plating", 
                             "Nexus Armor", "Compressed Nexus Armor", "Merged Nexus Armor", "Neutronium Armor", "Core Neutronium Armor", "Deep Core Neutronium Armor", 
                             "Fermionic Armor", "Stabilized Fermionic Armor", "Perfect Fermionic Armor", "Syncopated Plating", "Stabilized Syncopated Plating", "Perfect Syncopated Plating"};
        String[] reactorname = {"Fusion Reactor", "Fusion Reactor Mark II", "Fusion Reactor Mark III", "Fusion Reactor Mark IV", 
                                "Graviton Core", "Graviton Core Mark II", "Graviton Core Mark III", "Graviton Core Mark IV", 
                                "Quantum Capacitor", "Quantum Capacitor Mark II", "Quantum Capacitor Mark III", "Quantum Capacitor Mark IV", 
                                "Antimatter Reactor", "Antimatter Reactor Mark II", "Antimatter Reactor Mark III", "Antimatter Reactor Mark IV", 
                                "Singularity Core", "Singularity Core Mark II", "Singularity Core Mark III", "Singularity Core Mark IV", 
                                "Zero-Point Reactor", "Zero-Point Reactor Mark II", "Zero-Point Reactor Mark III", "Zero-Point Reactor Mark IV", 
                                "Dark Energy Core", "Dark Energy Core Mark II", "Dark Energy Core Mark III", "Dark Energy Core Mark IV", 
                                "Intra-D Collider", "Intra-D Collider Mark II", "Intra-D Collider Mark III", "Intra-D Collider Mark IV", 
                                "Supernova Generator", "Supernova Generator Mark II", "Supernova Generator Mark III", "Supernova Generator Mark IV", 
                                "Proxy-Universe Reactor", "Proxy-Universe Reactor Mark II", "Proxy-Universe Reactor Mark III", "Proxy-Universe Reactor Mark IV"};
        String[] scanname = {"Proximity Sensor", "Proximity Sensor Mark II", "EM Scanner", "EM Scanner Mark II", "EM Scanner Mark III", "Wideband Scanner", "Wideband Scanner Mark II", "Wideband Scanner Mark III", 
                             "Multiwave Sensor", "Multiwave Sensor Mark II", "Multiwave Sensor Mark III", "Subspace Sensor", "Subspace Sensor Mark II", "Subspace Sensor Mark III", "Quantum Resonance Sensor", "Quantum Resonance Sensor Mark II",
                             "Quantum Resonance Sensor Mark III", "Sub-Dimensional Sensor", "Sub-Dimensional Sensor Mark II", "Sub-Dimensional Sensor Mark III", "Tachyon Sensor", "Tachyon Sensor Mark II", "Tachyon Sensor Mark III",
                             "X-Manifold Detector", "X-Manifold Detector Mark II", "X-Manifold Detector Mark III", "Hyperflux Sensor", "Hyperflux Sensor Mark II", "Hyperflux Sensor Mark III", "Continuum Analyzer", "Continuum Analyzer Mark II",
                             "Continuum Analyzer Mark III"};
        String[] cloakname = {"EM Absorbant Panels", "EM Absorbant Panels Mark II", "EM Absorbant Panels Mark III", "Refraction Panels Mark II", "Refraction Panels Mark III", "EM Adaptive Panels",
                              "EM Adaptive Panels Mark II", "EM Adaptive Panels Mark III", "Stealth Field Emitter", "Stealth Field Emitter Mark II", "Stealth Field Emitter Mark III", "Cloak Field Generator",
                              "Cloak Field Generator Mark II", "Cloak Field Generator Mark III", "Dimensional Masking", "Dimensional Masking Mark II", "Dimensional Masking Mark III"};
        String[] jamname = {"Proximity Jammer", "Proximity Jammer Mark II", "Sensor Jammer", "Sensor Jammer Mark II", "Sensor Jammer Mark III", "Wideband Jammer", "Wideband Jammer Mark II", 
                            "Wideband Jammer Mark III", "Quantum Jammer", "Quantum Jammer Mark II", "Quantum Mark III", "Subspace Jammer", "Subspace Jammer Mark II", "Subspace Jammer Mark III", 
                            "Anti-Tachyon Jammer", "Anti-Tachyon Jammer Mark II", "Anti-Tachyon Jammer Mark III", "Inverse Flux Jammer", "Inverse Flux Jammer Mark II", "Inverse Flux Jammer Mark III"};
        
        int[] atkrating = {1,2,3,5,7,12,15,18,25,29,33,42,47,52,63,69,75,88,95,
                          102,117,125,133,150,159,168,187,197,207,228,239,250,
                          274,287,300,328,343,358,391,409,427};
        int[] thrustrating = {6,10,14,84,94,104,176,190,204,300,318,336,456,478,500,720,770,820};
        int[] damprating = {1,2,24,30,36,50,58,6,126,138,150,234,250,266,374,394,414,552,590,626};
        int[] hullrating = {20,25,30,45,55,65,90,105,120,155,175,195,240,265,290,345,375,405,470,
                           505,540,615,644,695,785,835,885,985,1045,1105};
        int[] reactorrating = {10,13,16,19,23,27,31,35,40,45,50,55,62,69,76,83,93,103,113,123,136,149,
                              162,175,191,207,223,239,258,277,296,315,337,359,381,403,442,470,500,540};
        int[] scanrating = {4,9,20,26,32,46,53,62,80,90,100,124,138,152,186,206,226,272,298,324,382,414,
                           446,516,554,592,670,712,756,836,895,960};
        int[] cloakrating = {10,13,16,40,45,50,93,103,113,191,207,223,337,359,381,553,587,621};
        int[] jamrating = {3,5,23,27,31,62,69,76,136,149,162,258,277,296,435,463,491,691,726,761};
        
        int[] atksize = {3,4,5,6,7,9,10,11,13,14,15,17,18,19,21,22,23,25,26,27,
                        29,30,31,33,34,35,37,38,39,41,42,43,45,46,47,49,50,51,53,54,55};
        int[] thrustsize = {10,12,14,34,36,38,50,52,54,66,68,70,82,84,86,98,100,102};
        int[] dampsize = {3,5,18,20,22,26,28,30,42,44,46,58,60,62,74,76,78,90,92,94};
        int[] hullsize = {5,6,7,9,10,11,13,14,15,17,18,19,21,22,23,25,26,27,29,30,31,33,34,35,37,38,39,41,42,43};
        int[] reactorsize = {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};
        int[] scansize = {5,10,20,22,24,28,30,32,36,38,40,44,46,48,52,54,56,60,62,64,68,70,72,76,78,80,84,86,88,92,94,96};
        int[] cloaksize = {10,11,12,18,19,20,26,27,28,34,35,36,42,43,44,50,51,52};
        int[] jamsize = {4,6,14,15,16,22,23,24,30,31,32,38,39,40,46,47,48,54,55,56};
	
        private Module[] attack = new Module[atkname.length];
	private Module[] thrusters = new Module[thrustname.length];
	private Module[] dampeners = new Module[dampname.length];
	private Module[] armor = new Module[hullname.length];
	private Module[] reactor = new Module[reactorname.length];
	private Module[] scanner = new Module[scanname.length];
	private Module[] cloaking = new Module[cloakname.length];
	private Module[] jammer = new Module[jamname.length];
        
        
        
        // create fields for data
        private JFormattedTextField atkfield;
        private JFormattedTextField thrustfield;
        private JFormattedTextField dampfield;
        private JFormattedTextField hullfield;
        private JFormattedTextField reactorfield;
        private JFormattedTextField scanfield;
        private JFormattedTextField cloakfield;
        private JFormattedTextField jamfield;
        JTextArea results;
        
        //values for fields
        private int atk = 0;
        private int thrust = 0;
        private int damp = 0;
        private int hull = 0;
        private int react = 0;
        private int scan = 0;
        private int cloak = 0;
        private int jam = 0;
        
        //labels for fields
        private JLabel atkLabel;
        private JLabel thrustLabel;
        private JLabel dampLabel;
        private JLabel hullLabel;
        private JLabel reactLabel;
        private JLabel scanLabel;
        private JLabel cloakLabel;
        private JLabel jamLabel;
        
        //Strings for labels
        private static String atkString = "Attack Modules: Max 8";
        private static String thrustString = "Thruster Modules: Max 4";
        private static String dampString = "Dampener Modules: Max 4";
        private static String hullString = "Armor Modules: Max 5";
        private static String reactString = "Reactor Modules: Max 3";
        private static String scanString = "Scanner Modules: Max 5";
        private static String cloakString = "Cloaking Modules: Max 2";
        private static String jamString = "Jammer Modules: Max 2";
        
        //format and parse numbers
        private NumberFormat atkFormat;
        private NumberFormat thrustFormat;
        private NumberFormat dampFormat;
        private NumberFormat hullFormat;
        private NumberFormat reactFormat;
        private NumberFormat scanFormat;
        private NumberFormat cloakFormat;
        private NumberFormat jamFormat;
        
        //create buttons
        private JComboBox atkbox = new JComboBox(attack);
        private JComboBox thrustbox = new JComboBox(thrusters);
        private JComboBox dampbox = new JComboBox(dampeners);
        private JComboBox hullbox = new JComboBox(armor);
        private JComboBox reactorbox = new JComboBox(reactor);            
        private JComboBox scanbox = new JComboBox(scanner);            
        private JComboBox cloakerbox = new JComboBox(cloaking);            
        private JComboBox jambox = new JComboBox(jammer);            
        private JButton calculate = new JButton("Calculate");

	public class GridBagFrame extends JFrame{
        private GridBagLayout layout;
        private GridBagConstraints constraints;
        

        public GridBagFrame(){
            super("Ship Builder");
            layout = new GridBagLayout();
            setLayout(layout);
            constraints = new GridBagConstraints();
            setUpFormats();
            
            for (int i = 0; i < attack.length; i++) {
                attack[i] = new Module(atkname[i],atksize[i],atkrating[i]);
            }
            for (int i = 0; i < thrusters.length; i++) {
                thrusters[i] = new Module(thrustname[i],thrustsize[i],thrustrating[i]);
            }
            for (int i = 0; i < dampeners.length; i++) {
                dampeners[i] = new Module(dampname[i],dampsize[i],damprating[i]);
            }
            for (int i = 0; i < armor.length; i++) {
                armor[i] = new Module(hullname[i],hullsize[i],hullrating[i]);
            }
            for (int i = 0; i < reactor.length; i++) {
                reactor[i] = new Module(reactorname[i],reactorsize[i],reactorrating[i]);
            }
            for (int i = 0; i < scanner.length; i++) {
                scanner[i] = new Module(scanname[i],scansize[i],scanrating[i]);
            }
            for (int i = 0; i < cloaking.length; i++) {
                cloaking[i] = new Module(cloakname[i],cloaksize[i],cloakrating[i]);
            }
            for (int i = 0; i < jammer.length; i++) {
                jammer[i] = new Module(jamname[i],jamsize[i],jamrating[i]);
            }
            //create labels
            atkLabel = new JLabel(atkString);
            thrustLabel = new JLabel(thrustString);
            dampLabel = new JLabel(dampString);
            hullLabel = new JLabel(hullString);
            reactLabel = new JLabel(reactString);
            scanLabel = new JLabel(scanString);
            cloakLabel = new JLabel(cloakString);
            jamLabel = new JLabel(jamString);
            
            //create text fields and set them up
            atkfield = new JFormattedTextField(atkFormat);
            atkfield.setValue(new Integer(atk));
            atkfield.setColumns(2);
            
            
            thrustfield = new JFormattedTextField(thrustFormat);
            thrustfield.setValue(new Integer(thrust));
            thrustfield.setColumns(2);
            
            
            dampfield = new JFormattedTextField(dampFormat);
            dampfield.setValue(new Integer(damp));
            dampfield.setColumns(2);
            
            
            hullfield = new JFormattedTextField(hullFormat);
            hullfield.setValue(new Integer(hull));
            hullfield.setColumns(2);
            
            
            reactorfield = new JFormattedTextField(reactFormat);
            reactorfield.setValue(new Integer(react));
            reactorfield.setColumns(2);
            
            
            scanfield = new JFormattedTextField(scanFormat);
            scanfield.setValue(new Integer(scan));
            scanfield.setColumns(2);
            
            
            cloakfield = new JFormattedTextField(cloakFormat);
            cloakfield.setValue(new Integer(cloak));
            cloakfield.setColumns(2);
            
            
            jamfield = new JFormattedTextField(jamFormat);
            jamfield.setValue(new Integer(jam));
            jamfield.setColumns(2);
            

            
            
            //add components
            addComponent(atkLabel,0,5,1,1);
            addComponent(atkbox, 1,1,3,1);
            addComponent(atkfield, 1,5,1,1);
            
            addComponent(thrustLabel,3,5,1,1);
            addComponent(thrustbox,4,1,3,1);
            addComponent(thrustfield, 4,5,1,1);
            
            addComponent(dampLabel,6,5,1,1);
            addComponent(dampbox,7,1,3,1);
            addComponent(dampfield, 7,5,1,1);
            
            addComponent(hullLabel,9,5,1,1);
            addComponent(hullbox,10,1,3,1);
            addComponent(hullfield, 10,5,1,1);
            
            addComponent(reactLabel,12,5,1,1);
            addComponent(reactorbox,13,1,3,1);
            addComponent(reactorfield, 13,5,1,1);
            
            addComponent(scanLabel,15,5,1,1);
            addComponent(scanbox,16,1,3,1);
            addComponent(scanfield, 16,5,1,1);
            
            addComponent(cloakLabel,18,5,1,1);
            addComponent(cloakerbox,19,1,3,1);
            addComponent(cloakfield, 19,5,1,1);
            
            addComponent(jamLabel,21,5,1,1);
            addComponent(jambox,22,1,3,1);
            addComponent(jamfield, 22,5,1,1);
            
            //tell accessibility tools about label/textfield pairs
            atkLabel.setLabelFor(atkfield);
            thrustLabel.setLabelFor(thrustfield);
            dampLabel.setLabelFor(dampfield);
            hullLabel.setLabelFor(hullfield);
            reactLabel.setLabelFor(reactorfield);
            scanLabel.setLabelFor(scanfield);
            cloakLabel.setLabelFor(cloakfield);
            jamLabel.setLabelFor(jamfield);
            
            constraints.weightx = 0;
            constraints.weighty = 0;
            constraints.fill = GridBagConstraints.NONE;
            addComponent(calculate,24,5,1,1);
            calculate.addActionListener(new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent a){
                    //retrieve size and rating from each combo box;
                    Module getAtk = (Module)atkbox.getSelectedItem();
                    int atkMsize = getAtk.getSize();
                    int atkMrate = getAtk.getRating();
                    Module getThrust = (Module)thrustbox.getSelectedItem();
                    int thrustMsize = getThrust.getSize();
                    int thrustMrate = getThrust.getRating();
                    Module getDamp = (Module)dampbox.getSelectedItem();
                    int dampMsize = getDamp.getSize();
                    int dampMrate = getDamp.getRating();
                    Module getHull = (Module)hullbox.getSelectedItem();
                    int hullMsize = getHull.getSize();
                    int hullMrate = getHull.getRating();
                    Module getReactor = (Module)reactorbox.getSelectedItem();
                    int reactMsize = getReactor.getSize();
                    int reactMrate = getReactor.getRating();
                    Module getScanner = (Module)scanbox.getSelectedItem();
                    int scanMsize = getScanner.getSize();
                    int scanMrate = getScanner.getRating();
                    Module getCloaker = (Module)cloakerbox.getSelectedItem();
                    int cloakMsize = getCloaker.getSize();
                    int cloakMrate = getCloaker.getRating();
                    Module getJammer = (Module)jambox.getSelectedItem();
                    int jamMsize = getJammer.getSize();
                    int jamMrate = getJammer.getRating();
            
                    //calculate total size and rating for each module and calculate total decks used
                    int atkTsize = atkMsize * Integer.parseInt(atkfield.getText());
                    int thrustTsize = thrustMsize * Integer.parseInt(thrustfield.getText());
                    int dampTsize = dampMsize * Integer.parseInt(dampfield.getText());
                    int hullTsize = hullMsize * Integer.parseInt(hullfield.getText());
                    int reactTsize = reactMsize * Integer.parseInt(reactorfield.getText());
                    int scanTsize = scanMsize * Integer.parseInt(scanfield.getText());
                    int cloakTsize = cloakMsize * Integer.parseInt(cloakfield.getText());
                    int jamTsize = jamMsize * Integer.parseInt(jamfield.getText());
            
                    int decksUsed = atkTsize + thrustTsize + dampTsize + hullTsize + reactTsize + 
                            scanTsize + cloakTsize + jamTsize;
            
                    int atkTrate = atkMrate * Integer.parseInt(atkfield.getText());
                    int thrustTrate = thrustMrate * Integer.parseInt(thrustfield.getText());
                    int dampTrate = dampMrate * Integer.parseInt(dampfield.getText());
                    int hullTrate = hullMrate * Integer.parseInt(hullfield.getText());
                    int reactTrate = reactMrate * Integer.parseInt(reactorfield.getText());
                    int scanTrate = scanMrate * Integer.parseInt(scanfield.getText());
                    int cloakTrate = cloakMrate * Integer.parseInt(cloakfield.getText());
                    int jamTrate = jamMrate * Integer.parseInt(jamfield.getText());  
                    int defTrate = thrustTrate + dampTrate;                         //calculate total defense
                    int cloakingTrate = cloakTrate + jamTrate;                      //calculate total cloak
                    results = new JTextArea("Decks Used: " + decksUsed + "\n" + "Attack Rating: " + atkTrate + "\n"
                            + "Defense Rating: " + defTrate + "\n" + "Total Hull: " + hullTrate + "\n" +
                            "Total Energy: " + reactTrate + "\n" + "Total Scan: " + scanTrate + "\n" +
                            "Total Cloak: " + cloakingTrate);
                }
            });
        }

        private void addComponent(Component component, int row, int column, int width, int height){
            constraints.gridx = column;
            constraints.gridy = row;
            constraints.gridwidth = width;
            constraints.gridheight = height;
            layout.setConstraints(component, constraints);
            add(component);
        }
    }

        private void setUpFormats(){
            atkFormat = NumberFormat.getNumberInstance();
            thrustFormat = NumberFormat.getNumberInstance();
            dampFormat = NumberFormat.getNumberInstance();
            hullFormat = NumberFormat.getNumberInstance();
            scanFormat = NumberFormat.getNumberInstance();
            reactFormat = NumberFormat.getNumberInstance();
            cloakFormat = NumberFormat.getNumberInstance();
            jamFormat = NumberFormat.getNumberInstance();
        }

	public static void main(String args[]){
            
            Shipbuilder b = new Shipbuilder();
            GridBagFrame gridBagFrame = b.new GridBagFrame();
            gridBagFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gridBagFrame.setSize(500, 500);
            gridBagFrame.setVisible(true);
	}
}

Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Array not filling

Posted 09 August 2012 - 07:50 PM

Doesn't compile. What's this?

        
        private Module ;
        private Module ;
        private Module ;
        private Module ;
        private Module ;
        private Module ;
        private Module ;
        private Module ;
        


Was This Post Helpful? 0
  • +
  • -

#5 slacman69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-July 12

Re: Array not filling

Posted 09 August 2012 - 08:04 PM

Module is the class that has the constructor and methods for my arrays. That section should be lines 75-82.
Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Array not filling

Posted 09 August 2012 - 08:05 PM

Sorry... For some reason the code appeared that way on my PC. No problems.

This post has been edited by blackcompe: 09 August 2012 - 08:07 PM

Was This Post Helpful? 0
  • +
  • -

#7 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1009
  • View blog
  • Posts: 2,186
  • Joined: 05-May 05

Re: Array not filling

Posted 09 August 2012 - 08:24 PM

The issue is that you're constructing the combo box with an array of Modules. Generally, Strings go in combo boxes.

private JComboBox atkbox = new JComboBox(new String[]{"attack1", "attack2", "attack3"});


I really don't know the usage details for the new generic implementation of combo boxes or even why they genercized it to begin with, so that's the only alternative I can suggest. Have you look through the Java tutorials? Plenty of GUI examples there.

Just a guess, but if you construct a combo box with something other than strings, you may need to provide a renderer as well.

This post has been edited by blackcompe: 09 August 2012 - 08:26 PM

Was This Post Helpful? 0
  • +
  • -

#8 slacman69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-July 12

Re: Array not filling

Posted 09 August 2012 - 08:29 PM

I was able to display it before so I am not sure why it is not displaying now.
Was This Post Helpful? 0
  • +
  • -

#9 slacman69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-July 12

Re: Array not filling

Posted 09 August 2012 - 08:51 PM

Ok I got my arrays to display after moving my buttons into the GridBagFrame. Now I am trying to get my calculate button to display the information in a textarea. How would I go about doing this?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1