简体   繁体   中英

Object[ ][ ] to a linked collection in Java

I have a array 2D of CellPanes, filled randomly. Background is a instance variable of CellPane, of type Color. How to remove elements that share the same value of Background?

public CellPane[][] board = new CellPane[ROWS][COLS]; private static final int ROWS = 4; private static final int COLS = 4; GridBagConstraints gbc;

public class CellPane extends JPanel
{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public ArrayList<Color> cores = new ArrayList<Color>();
    private Color Background;

In ArrayList cores, I have the Colors that I want the Background var to have. So, each element in array board have a different Background color. Now I want to make that if a element is selected, all elements adjacent to the original are removed, or changed to null. It's this part of linking elements that share the same value in Background that I need to do, but the elements must have the same position. Is it still unclear? Please comment if its unclear, I will try harder

You would have to do it manually, there is no function that has such an algorithm in the standard Java library. Aside from that, your question is not very clear. Do you want to have multiple Collections with each one having CellPanes of the same Background or do you want to have one Collection with some specific properties?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM