|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Java help ---A JButton array *FIXED*
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Well my prof. made it sound like it was possible to make an array of JButtons instead of naming 9 different buttons.
However I'm getting a NullPoinerException at line 98 where I'm adding the buttons to the JFrame.(in bold) Heres the code: Code:
JButton[] button =new JButton[9];
for(int i=0;i<button.length;++i){
this.add(button[i]);
}
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
Last edited by dangerousHobo : 04-06-07 at 01:12 AM. |
||||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||||
|
Photography nut
![]() |
FIXED:
Turns out I was only creating the array, but never the objects. Simple fix: Code:
JButton[] button = new JButton[9];
for(int i=0;i<button.length;++i){
button[i] = new JButton();
this.add(button[i]);
}
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#3 (permalink) | ||||||||||||
|
110100001101001111000
|
As you already know, you can make an array of buttons. I used it when I had to do an implementation of the basic Windows calculator. You can also make arrays of containers, panes, JTextFields and pretty well every other thing you can think of. It came in VERY handy when I did a Sudoku solver. 81 individual cells would have been a pain.
__________________
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|