saschaaaaa
Goto Top

Remove JPanel von dem ich nur die Pixel-Koordinaten weiß

Hallo,

ich habe ein JPanel mit dem Hintergrund Grün.
Darauf/Darin sind mehrere hundert JPanels (nennen wir sie "Mauern") die ein Spielfeld darstellen.
Erzeugt werden sie in For Schleifen, jede Mauer ist 50x50 pixel breit.

for(ganzes JPanel mit grünem hintergrund){
		JPanel pnl_inner = new JPanel();
		pnl_inner.setBackground(new Color(156, 158, 150));
		pnl_inner.setBounds(int_position_y, int_position_x, 50, 50);
		pnl_spielfeld.add(pnl_inner);
}

Ist es möglich das ich sage:
Das JPanel das bei den Koordinaten 150 (nach rechts) und 350 (nach unten) liegt löschen?

Auf dem Bild stehen Zahlen. Diese zeigen wie ich die "Koordinaten" anhand von Pixeln berechne.
Das rot Umramte JPanel möchte ich entfernen.

Wenn ja, wie geht das?

Mit freundlichen Grüßen
Sascha
unbenannt

Content-Key: 308370

Url: https://administrator.de/contentid/308370

Printed on: April 16, 2024 at 12:04 o'clock

Mitglied: 129813
129813 Jun 28, 2016 updated at 10:17:01 (UTC)
Goto Top
Hi.
I would put them into an a two dimensional array, while creating them. Then you can get access to all of them by indices.

Regards
Member: Saschaaaaa
Saschaaaaa Jun 28, 2016 updated at 11:51:56 (UTC)
Goto Top
That would be possible, but im having more than 1.255 pairs of coordinates. And its not easy to handle that much.

Every "Wall" is build out of 4 or 9 JPanel's.

Is there no way to get the ID of a JPanel at position x y?
Mitglied: 129813
129813 Jun 28, 2016 at 12:00:01 (UTC)
Goto Top
Zitat von @Saschaaaaa:

That would be possible, but im having more than 1.255 pairs of coordinates. And its not easy to handle that much.
???
Every "Wall" is build out of 4 or 9 JPanel's.
So only 36 panels
Is there no way to get the ID of a JPanel at position x y?
Iterate over all panels get their position rectangle and check if its in its range of the coords.
Member: Saschaaaaa
Saschaaaaa Jun 28, 2016 at 12:24:37 (UTC)
Goto Top
Zitat von @129813:

Zitat von @Saschaaaaa:

That would be possible, but im having more than 1.255 pairs of coordinates. And its not easy to handle that much.
???

19 Walls per Row
and 11 Walls per Line

19*11 = 209

4 OR 9 JPanels per Wall

209*4 = 836
209*9 = 1881

So im having between 1881 and 836 JPanels
Ever JPanel have one X and one Y Coordinate

Is there no way to get the ID of a JPanel at position x y?
Iterate over all panels get their position rectangle and check if its in its range of the coords.

If thats the fastest way i need to look for another solution :/
Mitglied: 129813
129813 Jun 28, 2016 updated at 12:29:30 (UTC)
Goto Top
Zitat von @Saschaaaaa:
If thats the fastest way i need to look for another solution :/
Better is what i said, use an array to store and access your panels, you could also store their coord range in an additional field if you wish. This would be strait forward and efficient ...