Java: Two problems about Swing and Variables

Discussion in 'Mac Programming' started by jsmwoolf, Aug 17, 2011.

  1. jsmwoolf macrumors regular

    Joined:
    Aug 17, 2011
    #1
    I'm somewhat new to Java, but I'm not new to programming as I know C, C++, and some Objective-C(the syntax is a bit too weird when you deal with classes).

    As my first program done in Java, I decided to program a GUI Calculator that can first do the simple stuff such as your arithmetics to complex functions such as your trig functions, logarithms, and squares to functions that can cover a concept(this one I'm still thinking about).

    Anyway, I have two problems that seem very weird.

    Problem #1: While this part isn't very critical, I decided to allow the user to customize the text color of the buttons. I stored a Color variable that colored the Foreground of the Buttons. However, after selecting a color, I tried to change the color of a button and it gives me a NullPointerException error. The error occurs at the line
    Code:
    control.gui.Digit1.setForeground(defaultColor)
    . This section means that it goes to the Control class(which I didn't post), then from the Control class to the Interface class(the main window and also another one that I didn't post), finds the JButton Digit1, and then changes the color of the text. The weird part is that if I create a constructor that goes to the Interface class, it gives me a NullPointerException error. Its even weirder that even trying to change a boolean value from true to false from the Preferences_Control to the Control class also gives me a NullPointerException error. The only time I can change a variable value without getting a NullPointerException is if I'm referring to the ColorSliders class.

    My code from the Preferences_Control class:
    Code:
    import java.awt.Color;
    
    public class Preferences_Control implements ActionListener {
    	Interface_Preferences gui;
    	public Control control;
    	ColorSliders color;
    	//The variables for this window
    	Color defaultColor = new Color(0,0,0); //For default
    	Color arithColor = new Color(255,0,0); //For arithmetic
    	Color functColor = new Color(0,0,255); //For Functions
    	
    	//Declares the function
    	public Preferences_Control(Interface_Preferences in)
    	{
    		gui = in;
    	}
    	
    	public Preferences_Control(Control in2)
    	{
    		control = in2;
    	}
    	
    	public Preferences_Control(ColorSliders in3)
    	{
    		color=in3;
    	}
    	
    	public void actionPerformed(ActionEvent input)
    	{
    		Object current = input.getSource();
    		if(current==gui.defaultColoring)
    		{
    			System.out.println(defaultColor);
    			ColorSliders color = new ColorSliders();
    			color.colorType=0;
    		}
    		if(current==gui.arithColoring)
    		{
    			System.out.println(arithColor);
    			ColorSliders color = new ColorSliders();
    			color.colorType=1;
    		}
    	}
    	
    	//This only works with the default color and can only be called from ColorSliders class
    	public void changeDefaultColor()
    	{
    		Color newColor = defaultColor;
    		//NOTE: control.gui.(...)-sends to the Interface control while gui.(..) goes to Interface Preferences
    		System.out.println("Changing the default color to " + newColor);
    		control.gui.Digit1.setForeground(newColor);
    		System.out.println("Done!");
    	}
    	
    	public void changeArithmeticColor(Color newColor)
    	{
    		System.out.println(arithColor);	
    		arithColor=newColor;
    		gui.paint();
    		System.out.println(arithColor);
    	}
    }
    Problem #2: When I change the variable color to something else and when I re-enter the ColorSliders window, the variable tends to always revert back to the default settings that is declared from the start of the program, even though I ran tests from the Preferences_Control and it shows that the color did change.

    The Code from ColorSliders class(I didn't code this section, but I did add to it):
    Code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class ColorSliders extends JFrame implements ChangeListener, ActionListener {
    	ColorPanel canvas = new ColorPanel();
    	Preferences_Control control = new Preferences_Control(this);
    	JSlider red = new JSlider(0,255,255);
    	JSlider green = new JSlider(0,255,0);
    	JSlider blue = new JSlider(0,255,0);
    	JButton done = new JButton("Done");
    	Color newColor = new Color(0,0,0);
    	int colorType=0;
    	public ColorSliders()
    	{
    		super("Color Slide");
    		setSize(270,300);
    		setUndecorated(true);
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setVisible(true);
    		
    		red.setMajorTickSpacing(50);
    		red.setMinorTickSpacing(10);
    		red.setPaintTicks(true);
    		red.setPaintLabels(true);
    		red.addChangeListener(this);
    		
    		green.setMajorTickSpacing(50);
    		green.setMinorTickSpacing(10);
    		green.setPaintTicks(true);
    		green.setPaintLabels(true);
    		green.addChangeListener(this);
    		
    		blue.setMajorTickSpacing(50);
    		blue.setMinorTickSpacing(10);
    		blue.setPaintTicks(true);
    		blue.setPaintLabels(true);
    		blue.addChangeListener(this);
    		
    		JLabel redLabel = new JLabel("Red: ");
    		JLabel greenLabel = new JLabel("Green: ");
    		JLabel blueLabel = new JLabel("Blue: ");
    		GridLayout grid = new GridLayout(5,1);
    		FlowLayout right = new FlowLayout(FlowLayout.RIGHT);
    		setLayout(grid);
    		
    		JPanel redPanel = new JPanel();
    		redPanel.setLayout(right);
    		redPanel.add(redLabel);
    		redPanel.add(red);
    		add(redPanel);
    		
    		JPanel greenPanel = new JPanel();
    		greenPanel.setLayout(right);
    		greenPanel.add(greenLabel);
    		greenPanel.add(green);
    		add(greenPanel);
    		
    		JPanel bluePanel = new JPanel();
    		bluePanel.setLayout(right);
    		bluePanel.add(blueLabel);
    		bluePanel.add(blue);
    		add(bluePanel);
    		add(canvas);
    		
    		JPanel donePanel = new JPanel();
    		donePanel.setLayout(right);
    		donePanel.add(done);
    		add(donePanel);
    		
    		done.addActionListener(this);
    		
    		setVisible(true);
    	}
    	
    	public void stateChanged(ChangeEvent event)
    	{
    		JSlider source = (JSlider) event.getSource();
    		if(source.getValueIsAdjusting() != true)
    		{
    			Color current = new Color(red.getValue(),green.getValue(),blue.getValue());
    			canvas.changeColor(current);
    			System.out.println(colorType);
    			//For default color
    			switch(colorType)
    			{
    			case 0:
    			{
    				System.out.println("The old color was " + control.defaultColor);
    				control.defaultColor = current;
    				System.out.println("The new color is " + control.defaultColor);
    				break;
    			}
    			case 1:
    			{
    				System.out.println("The old color was " + control.arithColor);
    				newColor = current;
    				System.out.println("The new color is " + newColor);
    				break;
    			}
    			}
    			canvas.repaint();
    		}
    	}
    	
    	public Insets getInsets()
    	{
    		Insets border = new Insets(45,10,10,10);
    		return border;
    	}
    	
    	public void actionPerformed(ActionEvent event)
    	{
    		String command = event.getActionCommand();
    		if(command.equals("Done"))
    		{
    			System.out.println("Invoked!");
    			if(colorType==0)
    			{
    				control.changeDefaultColor(); //Now goes to Preferences_Control and Preferences_Control will deal with the new color
    			}
    			if(colorType==1)
    			{
    				control.changeArithmeticColor(newColor);
    				System.out.println("Arithmetic color sucessful");
    			}
    			setVisible(false);
    		}
    	}
    }
    
    class ColorPanel extends JPanel
    {
    	Color background;
    
    	ColorPanel()
    	{
    		background = Color.red;
    	}
    	public void paintComponent(Graphics comp)
    	{
    		Graphics2D comp2D = (Graphics2D) comp;
    		comp2D.setColor(background);
    		comp2D.fillRect(0,0,getSize().width,getSize().height);
    	}
    	void changeColor(Color newBackground)
    	{
    		background = newBackground;
    	}
    }
    NOTE: The class Interface(which is not posted) contains the main() argument.
     
  2. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #2
    1. You have multiple constrictors. Most likely you are not using the one that initializes 'gui'. You can check this by checking to see if gui == null prior to calling the setForeground method

    2. This behavior is because you create a new instance of ColorSliders each time you enter the actionPerformed method. You may save a reference to the object instead and then just bring it up each time.
     
  3. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #3
    1. None of the Constructors go directly to the Interface class which is where the change is supposed to happen. It simply goes through the Control class and then from that class goes to the Interface class. Beside check whether gui == null is no use as it'll still give me a NullPointerException. Yet, I can't exactly check it at this instance because I'm now stump on the second part.

    2. How do I save a reference? By declaring only one object? I tried that, but it now gives a NullPointerException. I declared it in the Preferences_Control constructor of the ColorSliders argument but it doesn't recognize it. I also tried to declare it where I declare the variables and Objects, but then it won't even run. However, at this part

    The variable that I want to change isn't even in that class. It's in the Preferences_Control class which holds the variables for the colors.

    The changed code:

    Code:
    import java.awt.Color;
    import java.awt.event.*;
    
    public class Preferences_Control implements ActionListener {
    	Interface_Preferences gui;
    	public Control control;
    	ColorSliders color;
    	//The variables for this window
    	Color defaultColor = new Color(0,0,0); //For default
    	Color arithColor = new Color(255,0,0); //For arithmetic
    	Color functColor = new Color(0,0,255); //For Functions
    	
    	//Declares the function
    	public Preferences_Control(Interface_Preferences in)
    	{
    		gui = in;
    	}
    	
    	public Preferences_Control(Control in2)
    	{
    		control = in2;
    	}
    	
    	public Preferences_Control(ColorSliders in3)
    	{
    		color=in3;
    		ColorSliders colorSlide = new ColorSliders();
    	}
    	
    	public void actionPerformed(ActionEvent input)
    	{
    		Object current = input.getSource();
    		if(current==gui.defaultColoring)
    		{
    			System.out.println(defaultColor);
    			color.setVisible(true);
    			color.colorType=0;
    		}
    		if(current==gui.arithColoring)
    		{
    			System.out.println(arithColor);
    			color.setVisible(true);
    			color.colorType=1;
    		}
    	}
    	
    	//This only works with the default color and can only be called from ColorSliders class
    	public void changeDefaultColor()
    	{
    		Color newColor = defaultColor;
    		//NOTE: control.gui.(...)-sends to the Interface control while gui.(..) goes to Interface Preferences
    		System.out.println("Changing the default color to " + newColor);
    		control.gui.Digit1.setForeground(newColor);
    		System.out.println("Done!");
    	}
    	
    	public void changeArithmeticColor(Color newColor)
    	{
    		System.out.println(arithColor);	
    		arithColor=newColor;
    		gui.paint();
    		System.out.println(arithColor);
    	}
    }
    Or am I way off on what you meant? 99.9% that you can't put objects inside a constructor.
     
  4. naples98, Aug 18, 2011
    Last edited: Aug 18, 2011

    naples98 macrumors member

    naples98

    Joined:
    Sep 9, 2008
    Location:
    Houston
    #4
    See my comments in the code. Can you post the actual error message?

    Your null pointer exception is coming from control.gui.Digit1.setForeground(newColor); because you never initialize the "control" variable unless you call Preferences_Control() before.

     
  5. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #5
    The error if I put the ColorSliders object where I declare them.
    The question is how do I then declare them? If what I'm doing isn't declaring them, then what is it actually doing?

    Code:
    import java.awt.Color;
    import java.awt.event.*;
    
    public class Preferences_Control implements ActionListener {
    
            //These are initialized to null when you create class
            //They will continue to be null unless you call the first 3 methods         
            //(setters)
    	Interface_Preferences gui;
    	public Control control;
    	ColorSliders color;
    	ColorSliders colorSlide = new ColorSliders();
    	
            //The variables for this window
    	Color defaultColor = new Color(0,0,0); //For default
    	Color arithColor = new Color(255,0,0); //For arithmetic
    	Color functColor = new Color(0,0,255); //For Functions
    	
    	//Declares the function
    	public Preferences_Control(Interface_Preferences in)
    	{
    		gui = in;
    	}
    	
    	public Preferences_Control(Control in2)
    	{
    		control = in2;
    	}
    	
    	public Preferences_Control(ColorSliders in3)
    	{
    		color=in3;
    	}
    	
    	public void actionPerformed(ActionEvent input)
    	{
    		Object current = input.getSource();
    
    		if(current.equals(gui.defaultColoring))
    		{
    			System.out.println(defaultColor);
    			color.setVisible(true);
    			color.colorType=0;
    		}
    		if(current.equals(gui.arithColoring))
    		{
    			System.out.println(arithColor);
    			color.setVisible(true);
    			color.colorType=1;
    		}
    	}
    	
    	//This only works with the default color and can only be called from ColorSliders class
    	public void changeDefaultColor()
    	{
    
    		//NOTE: control.gui.(...)-sends to the Interface control while gui.(..) goes to Interface Preferences
    		System.out.println("Changing the default color to " + defaultColor);
    		control.gui.Digit1.setForeground(defaultColor);
    		System.out.println("Done!");
    	}
    	
    	public void changeArithmeticColor(Color newColor)
    	{
    		System.out.println(arithColor);	
    		arithColor=newColor;
    		gui.paint();
    		System.out.println(arithColor);
    	}
    }
     
  6. naples98 macrumors member

    naples98

    Joined:
    Sep 9, 2008
    Location:
    Houston
    #6
    Declaring a variable does not mean you are initializing it. They are different.

    You can write a constructor that initializes all

    Code:
    public Preferences_Control(Interface_Preferences gui, Control control, ColorSliders color)
    {
             this.gui = gui;
             this.control = control;
    	 this.color = color;
    }
    The reason you are getting the StackOverFlowError is because Preferences_Control creates an instance of ColorSliders which in turns creates an instance of Preferences_Control and so on until you fill up the stack.



     
  7. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #7
    Well, that gives the reason why I get an StackOverFlowError. However, how do I only declare and initialize the object once from the ColorSliders code?
     
  8. naples98 macrumors member

    naples98

    Joined:
    Sep 9, 2008
    Location:
    Houston
    #8
    Basically ColorSliders "has a" instance of Preferences_Control and Preferences_Control "has a" instance of ColorSliders.

    The way to fix it is to create an instance of whichever class is used first, and as a parameter to the constructor of the second class, which is called from the first class, pass in "this" of the first class then use that to initialize a class variable (of type of the first class) of the second class.

    Code:
    Class1
    {
     Class2 c2 = new Class2(this);
    }    
    
    Class2
    {
     Class1 c;
      public Class2(Class1 c1)
      {
      c = c1;
      }
    }
     
  9. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #9
    Thanks, it works and the arithmetic Color variable now holds on to new values other than the one that was assigned when the program is launched. However, I have a new problem and that 1st problem.

    New problem - while the arithmetic variable changes, when I click on an arithmetic function, it still changes the Foreground to the original color(which is red) even though this color change is supposed to change by the arithmetic color value held in the Preferences_Control class.

    The part that changes the Foreground in the Control class
    Code:
    gui.DigitAdd.setForeground(controlpref.arithColor);
    gui is the Interface class, DigitAdd is a JButton, and controlpref goes to the Preferences_Control class. This might be connected to the old problem.

    Old(1st) problem - I now ran a null test and it appears that the Control class(named control in the Preferences_Control class), is null. However, I though that we initialized the class from the Preferences_Control class, so I don't know what happened.
     
  10. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #10
    Post all of your code as it is now. We can't see the problem ourselves if we don't have the code.

    With that said... is this one of your first projects? It sounds like you're not really sure what's going on. I don't mean offense by this, I just mean to indicate that you may want to "step back" and work on some simpler problems before you bite off this big of a project. You're getting muddled in the complexity and having a hard time focusing on what the problem is.

    Are you using a debugger? What debugging steps are you using? Are you displaying all values in a chain working up step by step when you do a.b.c.d()? Are you displaying values throughout your program, or just right before things fail?

    -Lee
     
  11. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #11
    I'm not really stuck with a debugging plan. Yes, it's very foolish on my part. However, I tend to test the program whenever I add a feature. I'm using the console to see what's going on in the background such as whether variables are changing to the right numbers and if not, I check sections to determine what causes a specific code to function that way and I would adjust the conditions in order to make it run right.

    While I am new to Java and Swing, I'm not new to writing code as I know C, C++, Objective-C, and GML(Game maker Language), however GML is only practical in Game Maker which is made by YoyoGames and is only good for making games, not much else. Before learning Java, I used to do some problems from Project Euler, made a Rock-Paper-Sciccors game, a Tic-Tac-Toe game, and Amazon(not the website, but a riddle game) which I wrote in C, Objective-C, and Java.

    So I have done projects before, but this is my first big project.

    I'll instead post the project as one of the classes will probably be too long for the forum to accept.

    http://www.mediafire.com/?821953w99gh1ac2
     
  12. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #12
    Code:
    
    --- ../../../Downloads/SuperCalc-1/Calculator/Control.java	2011-08-18 20:18:47.000000000 -0500
    +++ ./Control.java	2011-08-18 22:36:33.000000000 -0500
    @@ -5,8 +5,8 @@
     public class Control implements ActionListener {
     	
     	Interface gui;
    -	Preferences_Control controlpref = new Preferences_Control(null,this,null);
    -	Interface_Preferences preferences = new Interface_Preferences();
    +	Preferences_Control controlpref = null;
    +	Interface_Preferences preferences = null;
     	//These are the variable that are needed to function for Interface and Control
     	boolean canAddDot=true; //used whether the user already used a dot
     	boolean isPositive=true; //used whether the number is positive or negative
    @@ -33,6 +33,9 @@
     	public Control(Interface in)
     	{
     		gui = in;
    +		controlpref = new Preferences_Control(this,null);
    +		preferences = new Interface_Preferences(controlpref);
    +		controlpref.setGUI(preferences);
     	}
     	
     	public void actionPerformed(ActionEvent event)
    diff -u ../../../Downloads/SuperCalc-1/Calculator/Interface_Preferences.java ./Interface_Preferences.java
    --- ../../../Downloads/SuperCalc-1/Calculator/Interface_Preferences.java	2011-08-18 17:53:23.000000000 -0500
    +++ ./Interface_Preferences.java	2011-08-18 22:22:59.000000000 -0500
    @@ -4,7 +4,7 @@
     
     public class Interface_Preferences extends JFrame{
     	
    -	Preferences_Control control = new Preferences_Control(this,null,null);
    +	Preferences_Control control = null;
     	//Option-Display
     	JPanel prefRow1 = new JPanel();
     	JLabel Option1 = new JLabel("Color:");
    @@ -12,9 +12,11 @@
     	JButton arithColoring = new JButton("Arithmetic Color");
     
     	
    -	public Interface_Preferences()
    +	public Interface_Preferences(Preferences_Control control)
     	{
     		super("Preferences");
    +		this.control = control;
    +		System.out.println("In Interfaces_Pref");
     		setSize(400,100);
     		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     		GridLayout layout = new GridLayout(1,1,1,1);
    diff -u ../../../Downloads/SuperCalc-1/Calculator/Preferences_Control.java ./Preferences_Control.java
    --- ../../../Downloads/SuperCalc-1/Calculator/Preferences_Control.java	2011-08-18 21:05:07.000000000 -0500
    +++ ./Preferences_Control.java	2011-08-18 22:33:34.000000000 -0500
    @@ -17,12 +17,17 @@
     	Color functColor = new Color(0,0,255); //For Functions
     	
     	//Declares the function
    -	public Preferences_Control(Interface_Preferences gui, Control control, ColorSliders color)
    +	public Preferences_Control(Control control, ColorSliders color)
     	{
    -	         this.gui = gui;
    +		 System.out.println("In Preferences_Control(Interface_P,Contr, ColorSliders)");
    +		 if(control == null) System.out.println("control is null!");
     	         this.control = control;
     	         this.color = color;
     	}
    +
    +	public void setGUI(Interface_Preferences gui) {
    +		this.gui = gui;
    +	}
     	
     	public void actionPerformed(ActionEvent input)
     	{
    
    
    I'm not sure if you can read diffs, but hopefully the unified style is clear enough. I left some of the debug in, but other than that there's probably a dozen material changes.

    You are doing a lot of initialization of member objects during initialization of an instance (but not in the constructor). This isn't awful, but it's unusual and led to a lot of errors. It seems that you're confusing an instance of an object, and the class itself. You were wanting to have one of a certain object, but ended up with different instances as members of other object instances, none of them tied together.

    The major change is to Preferences_Control and how it's initialized. It needs an Interface_Control and a Control, but you need a Preferences_Control to setup an Interface_Control. I chose to move setting the Interface_Control outside of the initializer. It's unfortunate, it might be nice to have some helper class that generates a "ControlBundle" in a single call so you can't accidentally set up a Preferences_Control without an Interface_Control.

    -Lee
     
  13. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #13
    Seems you ran this through terminal because half the mumbo jumbo is stuff that I can't make out.

    So let me see how this works.

    In the Control declaring, you set the Interface_Preferences and Preference_Control to null and then initialize them in the constructor like this. The possible reason why you set these to null is that you can declare them first and then, using a constructor, initialize them once so that you can't make repeats.

    Code:
    controlpref = new Preferences_Control(this,null);
    	preferences = new Interface_Preferences(controlpref);
            controlpref.setGUI(preferences);		              
    You then add another function in the Preferences_Control.

    For the Interface_Preferences, you do the same.

    For the Preferences_Control, you don't declare anything null, but you also get rid of the Interface_Preferences in the constructor and do a test to determine whether the control is null. However, what does the setGUI function do exactly?

    How come you declared Preferences_Control null twice(one in the Interface_Preferences and Control). I can understand why you declared Interface_Preferences once in the Control(the possible reason is because Control uses it whenever the user clicks the Preference Button), but not exactly the double Preferences_Control. I know that Control needs the Preferences_Control for colors and possibly other functions in the future, but why does Interface_Control need to declare a Preferences_Control as well because won't there be two Preferences_Control objects instead of one? Does it have to do with that setGUI function?
     
  14. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #14
    I lost a long post I'd be working on when my phone died.

    Short version:
    Object variables in Java are pointers. You don't get a new object when you declare a pointer to an object, only when you use new or a Factory method.
    You wanted a single instance of an object available multiple places. You were getting multiple objects with different members in different places. The changes I made pass the same object's address around and store it in variables so the same object can be accessed in multiple places.
    setGUI sets the gui member of a Preferences_Control object and sets it to the address of a Interface_Preferences that is passed in. The Interface_Preferences was initialized with the Preferences_Control object, making a circular reference between these two objects.

    Too tired to explain more, but the gist is that multiple declarations in different objects does not necessarily mean different objects, because they're pointers.

    -Lee
     
  15. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #15
    So, you created the Preferences_Control object in the Control class and then passed the object's address to the Interface_Preferences using a function through the Preferences_Control class. The connection was then initialized between Preferences_Control and Interface_Preferences through that function that you created rather than doing it through the constructor of the Preferences_Control.

    I'm only trying to interperate this process because it would be nice to exactly picture what's going on and a possibility to reuse this concept in future project.
     
  16. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #16
    This can surely be done more elegantly, but I was just trying to get this to work without completely changing it. Your interpretation is mostly correct, but:
    "connection was then initialized between Preferences_Control and Interface_Preferences" is a little odd in nomenclature, though you probably had the right intent. Also, the names you're using refer to the classes. It's important to understand that you're dealing with instances of these classes. Each object of these types has a member pointing at an object of the other type. Just these two objects reference one another, even if you only create one instance of each of these classes.

    -Lee
     
  17. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011
    #17
    Anyways, thanks for helping me and thanks for teaching me a valuable concept when programming in Java. Can this idea also help in other programming languages?
     
  18. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #18
    Any OOP language. If there are no Objects, there are no constructors, etc. You could have mutually referential structs in C, but it's probably less common.

    -Lee
     
  19. jsmwoolf thread starter macrumors regular

    Joined:
    Aug 17, 2011

Share This Page