Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Comprehension problem...  (Read 1496 times)
0 Members and 1 Guest are viewing this topic.
Offline hug0x

Senior Newbie





« Posted 2010-01-13 15:03:18 »

Hi everybody!  I still have the same problem..  Undecided

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 :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
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 :

1  
2  
3  
4  
5  
6  
7  
8  
9  
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  
51  
52  
53  
54  
55  
56  
57  
58  
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 :/
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #1 - Posted 2010-01-13 15:34:05 »

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

in your case, you should add this call :

1  
2  
3  
4  
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 .

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #2 - Posted 2010-01-13 17:42:35 »

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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hug0x

Senior Newbie





« Reply #3 - Posted 2010-01-13 18:09:02 »

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...  Undecided
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #4 - Posted 2010-01-13 18:16:26 »

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

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

JGO Coder


Medals: 5



« Reply #5 - Posted 2010-01-13 18:20:39 »

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.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #6 - Posted 2010-01-13 18:23:01 »

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...  Undecided

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 .

Offline pjt33
« Reply #7 - Posted 2010-01-14 12:38:20 »

The problem is your design. Have you worked through any of the Java Tutorial series?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!