• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPanel and JFrame

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i know what is the difference between a JPanel and a JFrame ...?
Is JPanel can allows us to manipulate the LayoutManager..?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JFrame is a window whereas a JPanel is only a container that can store other elements. A JPanel cannot be shown on the screen without it being placed in a window (like JFrame, JDialog, JWindow).

Moving to our UI forum.
 
Wen Hao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so we need to create a JFrame before we can use JPanel ..?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you need something to show on the screen. For Swing applications, that means JFrame, JDialog or JWindow, with JFrame being the most used.
 
Wen Hao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok ..~ here is my course assignment :

A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given a six cards in the deck, two might be labeled 1, two labeled 2, and two labeled 3. The cards are shuffled and placed face down on the table. A player then selects two cards that are face down, turns the face up, and if the cards match they are left face up. If the two cards do not match, they are returned to their original face down position. The game continues until all the cards are face up.

Write a program that plays the memory matching game. Use sixteen card that are laid out in a 4x4 square that are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that she would like to select through a coordinate system.
All of the cards that are face down are indicated by a *. The pairs of 8 which are face up are at coordinates (1,1) and (2,3). To hide the cards that have been temporarily places face up, output a large number of newlines to force the old board off the screen.

Hint: Use a 2D array for the arrangement of cards and another 2D array that indicates if a card is face up or down. Or, a more elegant solution is to create a single 2D array where each element is an object that stores both the card’s value and face. Write a function that “shuffles” the cards in the array.

i was advised that i can do it with JFrame , JPanel and JButton .

so , i have to create a JFrame for a window to display all the component , by using the JPanel with GridLayout to holds the JButton in the form im going to construct.
Is it like this..? I have zero experience on using Swing .
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short, yes. You add all buttons to the JPanel, which in turn you add to the JFrame, which in turn you show (setVisible(true)).

I suggest you read this to get started.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have been told to do it on the command line/terminal then you need to check with your lecturer/teacher before trying a Swing GUI.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case you already don't know it, the swing tutorial can be found here
 
Wen Hao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my lecturer announced she will give those who uses GUI some bonus mark..~
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> my lecturer announced she will give those who uses GUI some bonus mark..~

do you have the assignment completed? (forget the gui/bonus marks for the moment)

 
reply
    Bookmark Topic Watch Topic
  • New Topic