Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Sill constructors which don't work

Started by K_I_L_E_R Nov 22, 2003 at 8:09 AM 3 replies 300+ views
Original Post
K_I_L_E_R
K_I_L_E_R
Constructors in classes ''a'' and ''b'' do not initialise. Why is that? Thanks
public class d extends JFrame
{
	
	JList list1 = new JList();
	JList list2 = new JList();	
		
	d()
	{
		Container cont = getContentPane();
		JPanel pane = new JPanel();
		
		pane.add(list1);
		pane.add(list2);
		cont.add(pane);
		
		list1.setListData(RPG.a.a);
		list2.setListData(RPG.b.b);
		
		list1.updateUI();
		list2.updateUI();
		
	}
	
	public static void main(String[] args)
	{
		d frame = new d();
		frame.setVisible(true);
		frame.pack();
		frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	
	
}

class a
{
	static String a[] = new String[1];
	
	a()
	{
		a[0] = "F";
	}
	
	
}

class b
{
	static String b[] = new String[1];
	
	b()
	{
		b[0] = "A";
	}
	
}
 
NuffSaid
NuffSaid
Looking at your code, have you created new instances of a() and b()? The constructors only get called when you call new constructorname
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
K_I_L_E_R
K_I_L_E_R
Thanks.

I feel dissapointed that calling the string from the package doesn''t initiate the constructor.
CaptainJester
CaptainJester
quote:
Original post by K_I_L_E_R
Thanks.

I feel dissapointed that calling the string from the package doesn''t initiate the constructor.


Constructors are meant to set up a new object being created. For the functionality you want, you need to use a static block, as the AP said.



First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.