Comprehension problem...

Hi everybody! I still have the same problem… :-\

I know that’s a nooby problem, but nobody understand me…

So, I will explain you very simply…

I have 3 classes: A main, a frame and a Button class.

The main lauch the frame class with “frame f = new frame();”

The frame class create a frame with :


public class frame extends Button implements MouseListener, ActionListener{


	JFrame frame;



	
	public frame (){
		
		JPanel contenu;


		frame = new JFrame("Doode - Jeu");
		frame.setLayout(null);
		
		contenu = new JPanel();
				
		contenu.addMouseListener(this);
		
		 frame.setContentPane(contenu); 
		 

			frame.setSize(400,400);
			frame.setResizable(false);
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			frame.setVisible(true); 

Button b = new Button();
 
}}

The Button class create a JButton by :

public int CoorX=0;
public int CoorY=0;
JPanel contenu;
public JButton Doode = new JButton ("",new ImageIcon("DoodeImages/vert.gif"));



public Button(){
		System.out.print("doode crée ");

		Doode.setBounds(15,15,50,50);
		Doode.setFocusPainted(false);
		Doode.setBorderPainted(false);                  
		Doode.setContentAreaFilled(false);
		Doode.addMouseListener(this);
		Doode.setVisible(true);

}

public void mouseClicked(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}



public void mouseEntered(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}




public void mouseExited(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}



public void mousePressed(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}



public void mouseReleased(MouseEvent f) {
	Object source = f.getSource();	

	if(SwingUtilities.isRightMouseButton(f)) {

		CoorX=f.getX();
		CoorY=f.getY();
 }

}}


I want that everytime I put the line “Button v = new Button();” in the frame class, it show me a new button…

I hope this time you understood me :confused:

To show a button in a JPanel you should add it to the panel .

in your case, you should add this call :



Button b = new Button();

// add the button to a panel
contenu.add (b.Doode);



that’s a pretty bad design though. If you want your button to be a special kind of JButton, you should extend JButton .

I already showed you how to do this…

I thought I understood what you wanted(cause you said I was right).

you want a new one for every new time you make a doode right??

what was wrong with the code I gave you.

help me help you,
h3ckboy

EDIT:
hmm, I looked at the other thread, and saw you were asking…

for starters, why did you make a new thread?

second, you completely disregarded the code I gave you… I didnt see anything static, so I solved your problem, it just seems you dont want the solution I gave you?

h3ckboy, the code you gave me worked fine for define a new name for each button, but, these buttons don’t appear in my frame ^^

THe game don’t crash, but Jbutton “DoodeVert” aren’t in the frame… I tried to solve this problem by lots of way, and now, my code is crap and I think I have regressed… :-\

kk, thank you, if you had just said something I could have taken a look ;).

I will take another look now to see if I missed something.

well, I noticed some pretty deep design flaws in you code.

for starters, I couldnt find DoodeVerta declared anywhere, I did find DoodeVert, but not a DoodeVerta…

that would be an issue.

I will try and get something working from your code.

It will NOT appear if you don’t add it to the panel or the jframe. They way it is right you just create a button instance, and that’s it . You habe to add it to the pane, so the pane renderizes it .

By the way, you should play a little more with basic swing API before starting to build your own customized stuff .

The problem is your design. Have you worked through any of the Java Tutorial series?