![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Which class to extend?
I am working on an application similar to a tic-tac-toe game in Java. It will draw a number of squares in a window which will contain a number. The user should be able to click any one of these squares to select it and change its value by pressing a number key.
I want to create each of these squares as a separate object (that draws itself) so that I can easily modify the number they contain--for example, square1.setNumber(1). I don't have much experience working with GUI components in Java. What I am wondering is what class would be the best choice to extend as a square object--JPanel, JButton, JComponent, etc. Any ideas? Thanks... Also, objects I add to the content pane often don't display until I resize the window. Has anyone else had this problem? It has been happening ever since I started working with the GUI. Last edited by titaniumdecoy; Nov 29th, 2005 at 11:37 PM. |
|
|
|
|
|
#2 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4
![]() |
Quote:
Personally, I'd use one of the following:
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
If you can't see them until you resize the window, then there are any number of possible issues. The objects might be too big to be drawn within the window, so they don't show up until you make the window big enough, you may have bits of code interfering with each other, you have not yet discovered pack()..
It is also hard o say what classes you should extend, because we don't know what it is you are doing. When I do GUI, I often extend JFrame or JPanel, depending on what it is I am doing. But it is also a good way to introduce more problems. ![]()
__________________
HijackThis Team-SFDC |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|