Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help with JFrame and JPanel

 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, I have four classes one called Movie Player extends JFrame and the other thre called Button Panel, PicListPanel and Campanel and they extends JPanel, when I press the button it call a method that is in camp panel class the method sends the image name to another method in PicListPanel classe, a method in PicListPanel add a image to the GUI, but the picture in the Movie Player Classen not changed.










 
Piet Souris
Rancher
Posts: 1529
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Milad,

have a look at your ButtonPanel class.

In line 18, you define variable 'campan' to be of type CamPanel.
But that is all. Therefore you get a NullPE in line 55.

Make sure that 'campan' actually points to a real CamPanel.
Adding this real CamPanel via a parameter in the constructor
seems a nice way to get that done.

Greetz,
Piet

Edit: rereading this topic, I have no idea why I replied what I replied.
I have no clue as to what OP's problem is. I thought it was something
about a null pointer exception.

 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:hi Milad,

have a look at your ButtonPanel class.

In line 18, you define variable 'campan' to be of type CamPanel.
But that is all. Therefore you get a NullPE in line 55.

Make sure that 'campan' actually points to a real CamPanel.
Adding this real CamPanel via a parameter in the constructor
seems a nice way to get that done.

Greetz,
Piet

Edit: rereading this topic, I have no idea why I replied what I replied.
I have no clue as to what OP's problem is. I thought it was something
about a null pointer exception.



yes you are right but I fixed the problem and now it has this as a problem , thanks for the answer
 
Piet Souris
Rancher
Posts: 1529
33
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Milad,

first of all, don't change your post this way, since my reply now looks like nonsense.

You do not describe exactly what you do when the problem arises. For instance:
what button is getting pressed?

But if I look at your 'CamPanel' class, and the method 'TakePic' (line 58), you are
creating a PicListPanel p (line 76), you then call the method 'p.addlabel(...),
and then what? You do nothing with this PicListPanel p.

If you look at the method 'addlabel' of the PicListPanel class, you add a JLabel
to the panel, but that JLabel is an empty JLabel: see line 54. You forget the
parameter 'im' in your JLabel.

The 'revalidate' is okay, but what I do not see is how all your classes coöperate together.
I still see an NPE arising in your ButtonPnel class.

Hope I was of any help.

Greetz,
Piet
 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:hi Milad,

first of all, don't change your post this way, since my reply now looks like nonsense.

You do not describe exactly what you do when the problem arises. For instance:
what button is getting pressed?

But if I look at your 'CamPanel' class, and the method 'TakePic' (line 58), you are
creating a PicListPanel p (line 76), you then call the method 'p.addlabel(...),
and then what? You do nothing with this PicListPanel p.

If you look at the method 'addlabel' of the PicListPanel class, you add a JLabel
to the panel, but that JLabel is an empty JLabel: see line 54. You forget the
parameter 'im' in your JLabel.

The 'revalidate' is okay, but what I do not see is how all your classes coöperate together.
I still see an NPE arising in your ButtonPnel class.

Hope I was of any help.

Greetz,
Piet


thanks for replay, I want to make a stop-motion framework where someone can take pictures with their web camera then play those . I have four classer , Movie Player , CamPanel , PicListPanel and Button Panel . In my Button Panel is a actionPerformed method when I press the button ' take ' so call it the method TakePic located in CamPanel where I take a picture and writes it to a folder then sends images nam I it to PicListPanel where should I add it and show it.
 
Piet Souris
Rancher
Posts: 1529
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Milad,

I understand, and you're nearly there.

What you need to do is to get the four classes work together. That can be done in several ways.
One easy way would be to put a reference to 'campan' in your ButtonsPanel class.
You could achieve that, for instance, by supplying this 'campan' in the constructor of
ButtonsPanel. Say:

You must adapt class 'MoviePlayer' in that you first create a Campanel instance and
use that instance to create a ButtonsPanel instance.

In the 'addLabel' method of class 'PicListPanel', in line 54, use

Let us know if this makes your application work as you wnat it to work.

Greetz,
Piet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic