![]() |
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. |
Quote:
Personally, I'd use one of the following:
|
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. :) |
| All times are GMT -5. The time now is 3:29 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC