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

is the Jpanel class in the right place?

 
jon ninpoja
Ranch Hand
Posts: 198
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

just tinkering with swing,trying to build a basic GUI

i have a Jframe thats displaying a window
and from what i understand i need to create a Jpanel in order to put an image (jpg) onto it,tough i think i need a Jlabel to do that.

i see you cant just instantiate a Jpanel...you need to create a class that extends to Jpanel
(now i see why they call java a verbose language)

so i created a class that extends the Jpanel class.

does it just sit where i have it,or is there another way to do this?

heres my code:

this is what im wondering about

 
jon ninpoja
Ranch Hand
Posts: 198
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the code in code brackets,but it didnt come out like i hoped ...sorry
 
jon ninpoja
Ranch Hand
Posts: 198
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been meaning to ask

can you not edit a post once its posted

how do you get cows?
by helping other people?
 
Liutauras Vilda
Bartender
Pie
Posts: 2792
112
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Code tags need to suround your code

[Opening code tag]
some code
more code
[Closing code tag]

I've moved your thread to a more appropriate forum, which is related with GUI's, I hope you're fine with that.
 
Rob Camick
Ranch Hand
Posts: 2674
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see you cant just instantiate a Jpanel...


Of course you can just create a JPanel.

you need to create a class that extends to Jpanel


You do that when you have a logical reason for doing so. For example maybe you want an "AddressPanel" that contains fields for street, city, postal code etc all on the same panel.

Start by reading the Swing Tutorial for Swing basics of how to properly structure your code to create a frame. Some of the examples will extend a JPanel to add all the Swing components. Others will just create the panel and add components to the panel. Look for examples of both approaches.

Maybe the section on "How to Use Panels" would be a good place to start.

 
Campbell Ritchie
Sheriff
Posts: 51432
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:. . . i see you cant just instantiate a Jpanel...you need to create a class that extends to Jpanel
Who on earth told you that? There is no need to extend JPanel unless you need to override its paintComponent method or similar. Or add fields, as RC told youI cannot see why your present application needs a panel at all.
(now i see why they call java a verbose language) . . .
That is not what it means about being verbose. It means you cannot simply write
System.out.println("Hello, World.");
You have to write this sort of thing, too:-
 
Knute Snortum
Bartender
Pie
Posts: 2904
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:can you not edit a post once its posted

You can edit your posts for s short time after posting, if no one has posted a reply.  The reasoning is that it can make the subsequent posts nonsensical.  It's also to stop spammers. 

Two things you can do: before you post, use the Preview button and check your wording and code.  Otherwise just post your correction in a reply.

how do you get cows? by helping other people?

Cows are awarded by other users to signify some sort of excellence.  It might be a very well-worded question or a very helpful reply or something else.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic