Ajouter un commentaire

olihya
Inversion de cases dans un jtable

Bonjour à vous,
Bonjour Niroken,
Un grand merci pour le bout de code.:idea:
Je l'ai modifié pour faire l'inversion Horizontale.
J'ai voulu faire l'inversion en diagonale.
Je me disais que pour cela il fallait enchainer les 2 inversions verticale et horizontale.
Mais lorsque je les mets à la suite l'une de l'autre cela annule tout.
Est-ce qu'il y a un truc pour faire une première inversion horizontale et dans la foulée une verticale ou inversement.
Voici ou en ai mon ébauche:

[code]
package reverso;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Fenetre extends JFrame implements ActionListener, Icon {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel pan = new JPanel();
private JMenuBar barreMenus;
private JMenu niveaux;
private JMenu raz0;
private JMenu solu;
private JMenuItem raz;
private JMenuItem niv11, niv12, niv13, niv14;
private JMenuItem niveau1, niveau2, niveau3, niveau4;
private ImageIcon b1;
private ImageIcon b2;
private JButton[] b;
private String selectedNiveau;

// mise en place de la fenetre
public Fenetre() {

this.setTitle("Reverso");
this.setSize(450, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(true);
this.setLocationRelativeTo(null);
// mise en place des menus
barreMenus = new JMenuBar();
setJMenuBar(barreMenus);
niveaux = new JMenu("Niveaux");
raz0 = new JMenu("Reset");
solu = new JMenu("Solutions");
barreMenus.add(niveaux);
barreMenus.add(raz0);
barreMenus.add(solu);
raz = new JMenuItem("Raz");
raz0.add(raz);
raz.addActionListener(this);
niv11 = new JMenuItem("Niveau 1.1");
solu.add(niv11);
niv11.addActionListener(this);
niv12 = new JMenuItem("Niveau 1.2");
solu.add(niv12);
niv12.addActionListener(this);
niv13 = new JMenuItem("Niveau 1.3");
solu.add(niv13);
niv13.addActionListener(this);
niv14 = new JMenuItem("Niveau 1.4");
solu.add(niv14);
niv14.addActionListener(this);
niveau1 = new JMenuItem("Niveau1");
niveaux.add(niveau1);
niveau1.addActionListener(this);
niveau2 = new JMenuItem("Niveau2");
niveaux.add(niveau2);
niveau2.addActionListener(this);
niveau3 = new JMenuItem("Niveau3");
niveaux.add(niveau3);
niveau3.addActionListener(this);
niveau4 = new JMenuItem("Niveau4");
niveaux.add(niveau4);
niveau4.addActionListener(this);
// mise en place du gridLayout

// Message de bienvenue
JOptionPane
.showMessageDialog(pan,
"BIENVENU DANS LE JEU
VEUILLEZ SELECTIONNER UN NIVEAU.");
// positionnement des boutons sur le plateaux dans un tableau à une
// dimension sur un gridlayout
JButton[] b = new JButton[25];
this.b = b;
for (int i = 0; i < b.length; i++) {
b1 = new ImageIcon(getClass().getResource("b1.gif"));
b2 = new ImageIcon(getClass().getResource("b2.gif"));
b[i] = new JButton(b1);
b[i].setSelectedIcon(b2);
b[i].addActionListener(this);
pan.setLayout(new GridLayout(5, 5));
pan.add(b[i]);
}
setContentPane(pan);
}

{

this.setContentPane(pan);
this.setVisible(true);
}

// creation de la méthode de réinitialisation
private void reset() {
for (int i = 0; i < b.length; i++) {
b[i].setSelected(false);
}
}

private void resetsol() {
for (int i = 0; i < b.length; i++) {
b[i].setBackground(null);
}
}

private void inverseCasesVerticalement(int pTabLargeur, int pTabHauteur) {
JButton[] vButtons = new JButton[pTabLargeur * pTabHauteur];
pan.removeAll();

for (int i = 0; i < pTabHauteur; i++) {
for (int j = 0; j < pTabLargeur; j++) {
vButtons[(i * pTabHauteur) + j] = b[(i * pTabHauteur)
+ pTabLargeur - 1 - j];
pan.add(vButtons[(i * pTabHauteur) + j]);
}
}

b = vButtons;
pan.updateUI();
}

private void inverseCasesHorizontalement(int pTabLargeur, int pTabHauteur) {
JButton[] hButtons = new JButton[pTabLargeur * pTabHauteur];
pan.removeAll();

for (int i = 0; i < pTabHauteur; i++) {
for (int j = 0; j < pTabLargeur; j++) {
hButtons[(j * pTabLargeur) + i] = b[(j * pTabLargeur)
+ pTabHauteur - 1 - i];
pan.add(hButtons[(j * pTabLargeur) + i]);
}
}

b = hButtons;
pan.updateUI();

}

private void nive1() {
for (int i = 0; i < b.length; i++) {
b[1].setBackground(Color.magenta);
b[2].setBackground(Color.magenta);
b[4].setBackground(Color.magenta);
b[6].setBackground(Color.magenta);
b[7].setBackground(Color.magenta);
b[8].setBackground(Color.magenta);
b[12].setBackground(Color.magenta);
b[13].setBackground(Color.magenta);
b[14].setBackground(Color.magenta);
b[15].setBackground(Color.magenta);
b[16].setBackground(Color.magenta);
b[18].setBackground(Color.magenta);
b[19].setBackground(Color.magenta);
b[20].setBackground(Color.magenta);
b[21].setBackground(Color.magenta);
}
}

private void nive2() {
for (int i = 0; i < b.length; i++) {
b[3].setBackground(Color.magenta);
b[4].setBackground(Color.magenta);
b[5].setBackground(Color.magenta);
b[6].setBackground(Color.magenta);
b[8].setBackground(Color.magenta);
b[9].setBackground(Color.magenta);
b[10].setBackground(Color.magenta);
b[11].setBackground(Color.magenta);
b[12].setBackground(Color.magenta);
b[16].setBackground(Color.magenta);
b[17].setBackground(Color.magenta);
b[18].setBackground(Color.magenta);
b[20].setBackground(Color.magenta);
b[22].setBackground(Color.magenta);
b[23].setBackground(Color.magenta);
}
}

private void nive3() {
for (int i = 0; i < b.length; i++) {
b[0].setBackground(Color.magenta);
b[1].setBackground(Color.magenta);
b[5].setBackground(Color.magenta);
b[6].setBackground(Color.magenta);
b[8].setBackground(Color.magenta);
b[9].setBackground(Color.magenta);
b[12].setBackground(Color.magenta);
b[13].setBackground(Color.magenta);
b[14].setBackground(Color.magenta);
b[16].setBackground(Color.magenta);
b[17].setBackground(Color.magenta);
b[18].setBackground(Color.magenta);
b[21].setBackground(Color.magenta);
b[22].setBackground(Color.magenta);
b[24].setBackground(Color.magenta);
}
}

private void nive4() {
for (int i = 0; i < b.length; i++) {
b[0].setBackground(Color.magenta);
b[2].setBackground(Color.magenta);
b[3].setBackground(Color.magenta);
b[6].setBackground(Color.magenta);
b[7].setBackground(Color.magenta);
b[8].setBackground(Color.magenta);
b[10].setBackground(Color.magenta);
b[11].setBackground(Color.magenta);
b[12].setBackground(Color.magenta);
b[15].setBackground(Color.magenta);
b[16].setBackground(Color.magenta);
b[18].setBackground(Color.magenta);
b[19].setBackground(Color.magenta);
b[23].setBackground(Color.magenta);
b[24].setBackground(Color.magenta);
}
}

// creation de la méthode testant si tout les pions sont retournés
private boolean isAllGridSelected() {
boolean vResult = true;

for (int i = 0; i < b.length; i++) {
vResult = vResult && b[i].isSelected();
}

return vResult;
}

// gestion des évènements sur les boutons
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
if (source instanceof JMenuItem) {
if (source == raz) {
// mise en place de la méthode reset sur le JMenuitem raz
reset();
}
}
if (source instanceof JMenuItem) {
// remise à zéro à chaque sélection de niveau
reset();
resetsol();
// sélection des niveaux
if (source == niveau1) {
selectedNiveau = "niveau1";
JOptionPane
.showMessageDialog(
niveau1,
"NIVEAU 1
VOUS DEVEZ RETOURNER TOUT LES PIONS.
SACHANT QUE LORSQUE VOUS CLIQUEZ SUR UN PION,
LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI");

} else if (source == niveau2) {
selectedNiveau = "niveau2";
JOptionPane
.showMessageDialog(
niveau2,
"NIVEAU 2
VOUS DEVEZ RETOURNER TOUT LES PIONS.
LORSQUE VOUS CLIQUEZ SUR UN PION,
LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI
ET LA GRILLE PIVOTE SUR L'AXE VERTICAL.");

} else if (source == niveau3) {
selectedNiveau = "niveau3";
JOptionPane
.showMessageDialog(
niveau3,
"NIVEAU 3
VOUS DEVEZ RETOURNER TOUT LES PIONS.
LORSQUE VOUS CLIQUEZ SUR UN PION,
LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI
ET LA GRILLE PIVOTE SUR L'AXE HORIZONTAL.");

} else if (source == niveau4) {
selectedNiveau = "niveau4";
JOptionPane
.showMessageDialog(
niveau4,
"NIVEAU 4
VOUS DEVEZ RETOURNER TOUT LES PIONS.
LORSQUE VOUS CLIQUEZ SUR UN PION,
LES PIONS AU DESSUS, EN DESSOUS ET SUR LES CÔTES SE RETOURNENT AUSSI
ET LA GRILLE PIVOTE SUR LA DIAGONALE.");

}
if (source == niv11) {
selectedNiveau = "niv11";
JOptionPane
.showMessageDialog(
niv11,
"Solution 1.1
Selectionnez les pions ayant un fond magenta,
en partant du haut et en allant de gauche à droite.");

} else if (source == niv12) {
selectedNiveau = "niv12";
JOptionPane
.showMessageDialog(
niv12,
"Solution 1.2
Selectionnez les pions ayant un fond magenta,
en partant du haut et en allant de gauche à droite.");

} else if (source == niv13) {
selectedNiveau = "niv13";
JOptionPane
.showMessageDialog(
niv13,
"Solution 1.3
Selectionnez les pions ayant un fond magenta,
en partant du haut et en allant de gauche à droite.");

} else if (source == niv14) {
selectedNiveau = "niv14";
JOptionPane
.showMessageDialog(
niv14,
"Solution 1.4
Selectionnez les pions ayant un fond magenta,
en partant du haut et en allant de gauche à droite..");

}
// Gestion des inversions de pions des différents niveaux
} else if (source instanceof JButton) {

if (selectedNiveau.equals("niveau1")) {
for (int i = 6; i <= 8; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

// appel dela méthode isAllgGridSelected et affichage du message
// de fin de niveau
if (isAllGridSelected()) {
JOptionPane
.showMessageDialog(niveau1,
"BRAVO, C'EST GAGNE!!!
ESSAYEZ LE NIVEAU 2.");
}
}
if (selectedNiveau.equals("niveau2")) {
for (int i = 6; i <= 8; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

inverseCasesVerticalement(5, 5);
if (isAllGridSelected()) {
JOptionPane
.showMessageDialog(niveau2,
"BRAVO, C'EST GAGNE!!!
ESSAYEZ LE NIVEAU 3.");
}
}
}
if (selectedNiveau.equals("niveau3")) {

for (int i = 6; i <= 8; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

inverseCasesHorizontalement(5, 5);
if (isAllGridSelected()) {
JOptionPane
.showMessageDialog(niveau3,
"BRAVO, C'EST GAGNE!!!
ESSAYEZ LE NIVEAU 4.");
}
}
if (selectedNiveau.equals("niveau4")) {
for (int i = 6; i <= 8; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}

}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

inverseCasesHorizontalement(5, 5);
inverseCasesVerticalement(5, 5);

if (isAllGridSelected()) {
JOptionPane
.showMessageDialog(niveau4,
"BRAVO, C'EST GAGNE!!!
REVERSO N'A PLUS DE SECRET POUR VOUS.");
}
}
if (selectedNiveau.equals("niv11")) {
nive1();
for (int i = 6; i <= 8; i++) {

if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

// appel dela méthode isAllgGridSelected et affichage du message de
// fin de niveau
if (isAllGridSelected()) {
JOptionPane.showMessageDialog(niv11,
"ESSAYEZ LA SOLUTION DU NIVEAU 1.2");
}
}
if (selectedNiveau.equals("niv12")) {
nive2();
for (int i = 6; i <= 8; i++) {

if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

// appel dela méthode isAllgGridSelected et affichage du message de
// fin de niveau
if (isAllGridSelected()) {
JOptionPane.showMessageDialog(niv12,
"ESSAYEZ LA SOLUTION DU NIVEAU 1.3");
}
}
if (selectedNiveau.equals("niv13")) {
nive3();
for (int i = 6; i <= 8; i++) {

if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 4; i <= 4; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 20; i <= 20; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 24; i <= 24; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 1; i <= 3; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 5; i <= 5; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 10; i <= 10; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 15; i <= 15; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 21; i <= 23; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 9; i <= 9; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 14; i <= 14; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}
for (int i = 19; i <= 19; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
}
}

// appel dela méthode isAllgGridSelected et affichage du message de
// fin de niveau
if (isAllGridSelected()) {
JOptionPane.showMessageDialog(niv13,
"ESSAYEZ LA SOLUTION DU NIVEAU 1.4");
}
}
if (selectedNiveau.equals("niv14")) {
nive4();
for (int i = 6; i <= 8; i++) {

if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 11; i <= 13; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}

for (int i = 16; i <= 18; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelected());
b[i - 1].setSelected(!b[i - 1].isSelected());
b[i + 5].setSelected(!b[i + 5].isSelected());
b[i - 5].setSelected(!b[i - 5].isSelected());
}
}
for (int i = 0; i <= 0; i++) {
if (source == b[i]) {
b[i].setSelected(!b[i].isSelected());
b[i + 1].setSelected(!b[i + 1].isSelec

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 W     W  N   N  L     PPPP   L    
W W NN N L P P L
W W W N N N L PPPP L
W W W N NN L P L
W W N N LLLL P LLLL