myGully.com

myGully.com (https://mygully.com/index.php)
-   Programmierung (https://mygully.com/forumdisplay.php?f=67)
-   -   NetBeans - 2D Array Buttons (https://mygully.com/showthread.php?t=2064095)

pucci13 19.06.10 11:21

NetBeans - 2D Array Buttons
 
Hallo zusammen,

ich habe in NetBeans 100 Buttons (zehn waagerecht und zehn senkrecht) und ein zweidimensionales Array erstelt.
Nun würde ich gerne beides verbinden, aber ich weiß nicht wie.

Einem Button soll eine x/y-Koordinate zugeordnet werden.
Bsp.:
JButton1 soll die Koordinaten 0/0 haben
JButton2 soll die Koordinaten 0/1 haben
usw.

Kann mir vielleicht jemand weiterhelfen?


MfG

Madddin_89 31.07.10 22:06

Hi

so wie ich mir das gerade vorstelle, würd ich mir das Array
global anlegen. dann hängst du an jeden JButton logischerweise
einen MouseListener und über das ActionEvent kannst du
abfragen, welcher Button benutzt wurde und kannst dementsprechend
dein Array beschreiben...

Ich hoffe, dass ich dein Problem richtig verstanden habe und
meine Antwort dir bisschen geholfen hat :-)

Gruß
Madddin

urga 31.07.10 23:14

evntl. per simpler objektorientierung (wenn ich dein problem richtig verstanden habe)
Code:


public class myJButton extends JButton {
 public int x,y; // sollten eigentlich mind. protected sein incl. get/set-methoden ....
}
.....................
for (int x = 0; x < 10; x++) {
 for (int y = 0; y < 10; y++) {
  myJButton b = new  myJButton();
  b.x = x;
  b.y = y;
 }
}

oder auch
Code:


class myJButton extends JButton {
  public int x, y;
  public myJButton(int x, int y) {
  super(); // call JButton's constructor
  this.x = x;
  this.y = y;
 }
}
// ..............
myJButton b = new  myJButton(x,y);



Alle Zeitangaben in WEZ +1. Es ist jetzt 08:26 Uhr.

Powered by vBulletin® (Deutsch)
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.