GridLayout, gra, buttony SKACZACE PRZYCISKI

0

Chciałbym napisać minigierkę

Która ma polegać na:
Wybieram sobie rozmiar gry -> np 4x4 -1
Więc 15 elementów znajdzie się w niej
każdy element jest reprezentowany prze buttona i otrzymuje specjalne unikalne Id :]
czyli po prostu każdy button ma nr od 0-15 bez powtórzeń...
pozniej losujemy przypadkowe ułożenie przycisków...

i wygląda to tak

w przypadku 4x4

1 12 4 5
3 2 9 8
7 6 11 13
14 15 10

wylosowano i zaczynamy grę (tutaj stanąłem gdyż nie wiem jak usuwać komponenty, pobierając z GridLayout 'u

wklejam kod realizujący

losowanie oraz

//-------------------------------------------------


public class PRzyciskiView extends FrameView {

    public PRzyciskiView(SingleFrameApplication app) {
        super(app);

        initComponents();
        

        int lk,lw,liczba_kwadratow,wylosowane[];
        lk=lw=4;
        liczba_kwadratow = lk*lw - 1;
        mainPanel.setLayout(new GridLayout(lk,lw));
       

        wylosowane = losowanie(liczba_kwadratow);

            for (int i = 0 ; i<liczba_kwadratow;i++)
            {
                Button b1 =new Button(""+wylosowane[i]);
                b1.addActionListener(null);
                AL.add(b1);
                mainPanel.add(b1);
            }



        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = PRzyciskiApp.getApplication().getMainFrame();
            aboutBox = new PRzyciskiAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        PRzyciskiApp.getApplication().show(aboutBox);
    }
      public static int [] losowanie (int ile)
    {
    	Random Rn = new Random();
        int temp;
        boolean blad;
        int []tab;
        tab = new int[ile];

	for (int i=0; i<ile; i++)
	{

		do
		{
		blad=false;
		temp=Rn.nextInt(ile);
			for (int j=0; j<i; j++)
			{
				if (tab[j]==temp)
				{
				blad=true;
				}
			}
		} while (blad);
		tab[i]=temp;
	}

      for (int i=0; i<tab.length; i++)
          System.out.println("wynik[i] = " + tab[i]);

        return tab;
    }
```java
 

zadeklarowano również
//public ArrayList <Button> AL = new ArrayList();

0

usuwać ? setVisible(false) ?

1 użytkowników online, w tym zalogowanych: 0, gości: 1