Graphics bug on Win and Linux ?

Hi all,I have a graphic problem. I have created a JFrame and I have added him a JPanel (1) that it has as Layout a BorderLayout. To this JPanel (1) I have added another JPanel (2) that it has as Layout a GridLayout and a JLabel that I have used as StatusBar.

The problem is that when a window overlaps to the JPanel (1), the JPanel (2) is visualized to the initial state in which it had been created.After click on it returns to the actual state.

I post you an image to make to understand better me.

http://img176.imageshack.us/my.php?image=screenji3.gif

Someone know how i can resolve this problem?

Ps: sorry for my bad English.

Message was edited by:

JinKazama

I have forgotten to say that use Java5

[758 byte] By [JinKazamaa] at [2007-11-27 4:31:38]
# 1
> Someone know how i can resolve this problem?> I doubt if you will get a resolution unless you post your code.
sabre150a at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 2

/**

*

*/

package it.unibo.cs.CSameGame;

import javax.swing.JFrame;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFileChooser;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

import javax.swing.JMenuBar;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JLabel;

import javax.swing.JRadioButtonMenuItem;

import javax.swing.JTextField;

import javax.swing.JComboBox;

import javax.swing.JButton;

import javax.swing.KeyStroke;

import javax.swing.UIManager;

import java.awt.BorderLayout;

import java.awt.GridBagLayout;

import java.awt.GridBagConstraints;

import java.awt.GridLayout;

import java.awt.Insets;

import java.io.IOException;

import java.net.URL;

import java.security.NoSuchAlgorithmException;

import java.util.ArrayList;

import javax.swing.JCheckBox;

import java.awt.Toolkit;

/**

* @author Paolino Carmine

* @author Statuto Riccardo

*

*/

public class Swingui {

private JFrame FinestraPrincipale = null; // @jve:decl-index=0:visual-constraint="576,53"

private JMenuBar BarraMenu = null;

private JMenu Gioco = null;

private JMenuItem NuovoGioco = null;

private JMenu Impostazioni = null;

private JMenu Aiuto = null;

private JMenuItem About = null;

private JMenuItem Help = null;

private JMenuItem Esci = null;

private JMenuItem CaricaMappa = null;

private JMenuItem SalvaMappa = null;

private JMenuItem Settings = null;

private JFrame Preferenze = null; // @jve:decl-index=0:visual-constraint="10,10"

private JLabel L_lbl = null;

private JTextField L_txt = null;

private JLabel H_lbl = null;

private JTextField H_txt = null;

private JLabel N_lbl = null;

private JTextField N_txt = null;

private JLabel Stile_lbl = null;

private JComboBox Stile_cbox = null;

private JButton Salva_btn = null;

private static Game game; // @jve:decl-index=0:

private int l;

private int h;

private int n;

private int style;

private JPanel PrefContentPane = null;

private JPanel ContentPanePrincipale = null;

private JLabel StatusBarLabel = null;

private URL imageURL;

private ImageIcon image;

private JLabel piece;

private JLabel Player_lbl = null;

private JTextField Player_txt = null;

private String player;

private JMenu MenuTemi = null;

private JRadioButtonMenuItem Standard = null;

private JRadioButtonMenuItem Futurama = null;

private String tema = "base";

private JCheckBox NewGameAfterWinCB = null;

private JRadioButtonMenuItem KillBill = null;

private JPanel MainPanel = null;

private GridLayout LayoutGriglia;

private ArrayList<String> listaTipi = new ArrayList<String>();

private boolean flag;

/**

* This method initializes FinestraPrincipale

*

* @return javax.swing.JFrame

*/

private JFrame getFinestraPrincipale() {

if (FinestraPrincipale == null) {

try {

FinestraPrincipale = new JFrame();

FinestraPrincipale.setSize(new Dimension(374, 294)); // Generated

FinestraPrincipale.setTitle("CSameGame"); // Generated

FinestraPrincipale.setResizable(false);

FinestraPrincipale

.setIconImage(Toolkit

.getDefaultToolkit()

.getImage(

getClass()

.getResource(

"/it/unibo/cs/CSameGame/icons/face-surprise.png")));

FinestraPrincipale.setJMenuBar(getBarraMenu()); // Generated

FinestraPrincipale.setContentPane(getMainPanel()); // Generated

FinestraPrincipale

.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return FinestraPrincipale;

}

/**

* This method initializes BarraMenu

*

* @return javax.swing.JMenuBar

*/

private JMenuBar getBarraMenu() {

if (BarraMenu == null) {

try {

BarraMenu = new JMenuBar();

BarraMenu.add(getGioco()); // Generated

BarraMenu.add(getImpostazioni()); // Generated

BarraMenu.add(getAiuto()); // Generated

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return BarraMenu;

}

/**

* This method initializes Gioco

*

* @return javax.swing.JMenu

*/

private JMenu getGioco() {

if (Gioco == null) {

try {

Gioco = new JMenu();

Gioco.setText("Gioco"); // Generated

Gioco.setMnemonic(KeyEvent.VK_G);

Gioco.add(getNuovoGioco()); // Generated

Gioco.addSeparator();

Gioco.add(getCaricaMappa()); // Generated

Gioco.add(getSalvaMappa()); // Generated

Gioco.addSeparator();

Gioco.add(getEsci()); // Generated

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Gioco;

}

/**

* This method initializes NuovoGioco

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getNuovoGioco() {

if (NuovoGioco == null) {

try {

URL iconURL = getClass().getResource("icons/new.png");

Icon icon = new ImageIcon(iconURL);

NuovoGioco = new JMenuItem("Nuovo gioco", icon);

NuovoGioco.setMnemonic(KeyEvent.VK_N);

NuovoGioco.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,

ActionEvent.CTRL_MASK));

NuovoGioco.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

flag=true;

newGame();

}

});

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return NuovoGioco;

}

/**

* This method initializes Impostazioni

*

* @return javax.swing.JMenu

*/

private JMenu getImpostazioni() {

if (Impostazioni == null) {

try {

Impostazioni = new JMenu();

Impostazioni.setText("Impostazioni"); // Generated

Impostazioni.setMnemonic(KeyEvent.VK_I);

Impostazioni.add(getSettings()); // Generated

Impostazioni.add(getMenuTemi());

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Impostazioni;

}

/**

* This method initializes Aiuto

*

* @return javax.swing.JMenu

*/

private JMenu getAiuto() {

if (Aiuto == null) {

try {

Aiuto = new JMenu();

Aiuto.setText("Aiuto"); // Generated

Aiuto.setMnemonic(KeyEvent.VK_A);

Aiuto.add(getAbout()); // Generated

Aiuto.add(getHelp()); // Generated

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Aiuto;

}

/**

* This method initializes About

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getAbout() {

if (About == null) {

try {

About = new JMenuItem();

About.setText("Informazioni su..."); // Generated

About.setMnemonic(KeyEvent.VK_I);

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return About;

}

/**

* This method initializes Help

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getHelp() {

if (Help == null) {

try {

URL iconURL = getClass().getResource("icons/help.png");

Icon icon = new ImageIcon(iconURL);

Help = new JMenuItem("Aiuto CSameGame", icon);

Help.setMnemonic(KeyEvent.VK_A);

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Help;

}

/**

* This method initializes Esci

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getEsci() {

if (Esci == null) {

try {

URL iconURL = getClass().getResource("icons/exit.png");

Icon icon = new ImageIcon(iconURL);

Esci = new JMenuItem("Esci", icon);

Esci.setMnemonic(KeyEvent.VK_E);

Esci.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,

ActionEvent.CTRL_MASK));

Esci.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Esci;

}

/**

* This method initializes CaricaMappa

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getCaricaMappa() {

if (CaricaMappa == null) {

try {

URL iconURL = getClass().getResource("icons/open.png");

Icon icon = new ImageIcon(iconURL);

CaricaMappa = new JMenuItem("Carica partita...", icon);

CaricaMappa.setMnemonic(KeyEvent.VK_C);

CaricaMappa.setAccelerator(KeyStroke.getKeyStroke(

KeyEvent.VK_L, ActionEvent.CTRL_MASK));

CaricaMappa.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JFileChooser fc = new JFileChooser();

Filtro txtFiltro = new Filtro();

fc.setFileFilter(txtFiltro);

fc.addChoosableFileFilter(txtFiltro);

int scelta = fc.showOpenDialog(CaricaMappa);

try {

style = Stile_cbox.getSelectedIndex();

player = Player_txt.getText();

} catch (NullPointerException exception) {

player = "Anonimo";

}

if (scelta == JFileChooser.APPROVE_OPTION) {

try {

game = new Game(fc.getSelectedFile().getPath(),

style);

game.setPlayerName(player);

game.setPlayerScore();

StatusBarLabel.setText("Punteggio attuale: "

+ game.getPlayerScore());

printSurface();

SalvaMappa.setEnabled(true);

} catch (IOException exception) {

exception.printStackTrace();

} catch (StringIndexOutOfBoundsException exception) {

JOptionPane.showMessageDialog(null,

"Il file della mappa ?corrotto",

"Aiaiai...", JOptionPane.ERROR_MESSAGE);

} catch (NoSuchAlgorithmException exception) {

JOptionPane.showMessageDialog(null, exception

.toString().split(": ")[1],

"Aiaiai...", JOptionPane.ERROR_MESSAGE);

} catch (SecurityException exception) {

JOptionPane.showMessageDialog(null, exception

.toString().split(": ")[1],

"Aiaiai...", JOptionPane.ERROR_MESSAGE);

}

}

}

});

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return CaricaMappa;

}

/**

* This method initializes SalvaMappa

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getSalvaMappa() {

if (SalvaMappa == null) {

try {

URL iconURL = getClass().getResource("icons/save.png");

Icon icon = new ImageIcon(iconURL);

SalvaMappa = new JMenuItem("Salva partita...", icon);

SalvaMappa.setMnemonic(KeyEvent.VK_S);

SalvaMappa.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,

ActionEvent.CTRL_MASK));

SalvaMappa.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JFileChooser fc = new JFileChooser();

Filtro txtFiltro = new Filtro();

fc.setFileFilter(txtFiltro);

fc.addChoosableFileFilter(txtFiltro);

int scelta = fc.showSaveDialog(SalvaMappa);

SurfaceParser map = new SurfaceParser("");

if (scelta == JFileChooser.APPROVE_OPTION) {

try {

map.saveMap(fc.getSelectedFile().getPath(),

game.getSurface(), game.getH(), game

.getL(), game.getPlayerScore(),

style);

} catch (IOException exception) {

exception.printStackTrace();

} catch (NoSuchAlgorithmException exception) {

JOptionPane.showMessageDialog(null, exception

.toString().split(": ")[1],

"Aiaiai...", JOptionPane.ERROR_MESSAGE);

}

}

}

});

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return SalvaMappa;

}

/**

* This method initializes Settings

*

* @return javax.swing.JMenuItem

*/

private JMenuItem getSettings() {

if (Settings == null) {

try {

URL iconURL = getClass().getResource("icons/preferences.png");

Icon icon = new ImageIcon(iconURL);

Settings = new JMenuItem("Preferenze", icon);

Settings.setMnemonic(KeyEvent.VK_P);

Settings.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,

ActionEvent.CTRL_MASK));

Settings.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JFrame Preferenze = getPreferenze();

Preferenze.setVisible(true);

}

});

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return Settings;

}

/**

* This method initializes jTable

*

* @return javax.swing.JTable

*/

/**

* This method initializes Preferenze

*

* @return javax.swing.JFrame

*/

private JFrame getPreferenze() {

if (Preferenze == null) {

Preferenze = new JFrame("Preferenze");

Preferenze.setSize(new Dimension(530, 250));

Preferenze.setResizable(false); // Generated

Preferenze.setContentPane(getJContentPane()); // Generated

}

return Preferenze;

}

/**

* This method initializes L_txt

*

* @return javax.swing.JTextField

*/

private JTextField getL_txt() {

if (L_txt == null) {

L_txt = new JTextField("15");

}

return L_txt;

}

/**

* This method initializes H_txt

*

* @return javax.swing.JTextField

*/

private JTextField getH_txt() {

if (H_txt == null) {

H_txt = new JTextField("10");

}

return H_txt;

}

/**

* This method initializes N_txt

*

* @return javax.swing.JTextField

*/

private JTextField getN_txt() {

if (N_txt == null) {

N_txt = new JTextField("3");

}

return N_txt;

}

/**

* This method initializes Stile_cbox

*

* @return javax.swing.JComboBox

*/

private JComboBox getStile_cbox() {

if (Stile_cbox == null) {

String[] style = { "Standard", "Continous", "Megashift", "Shifter" };

Stile_cbox = new JComboBox(style);

}

return Stile_cbox;

}

/**

* This method initializes Salva_btn

*

* @return javax.swing.JButton

*/

private JButton getSalva_btn() {

if (Salva_btn == null) {

Salva_btn = new JButton();

Salva_btn.setText("Salva");

Salva_btn.addActionListener(new ActionListener() {

private Game fakegame;

public void actionPerformed(ActionEvent e) {

Preferenze.setVisible(false);

try {

l = Integer.parseInt(L_txt.getText());

h = Integer.parseInt(H_txt.getText());

n = Integer.parseInt(N_txt.getText());

style = Stile_cbox.getSelectedIndex();

player = Player_txt.getText();

fakegame = new Game(l, h, n, style);

fakegame.setPlayerName(player);

} catch (Exception expt) {

JOptionPane.showMessageDialog(null, expt.toString()

.split(": ")[1], "Aiaiai...",

JOptionPane.ERROR_MESSAGE);

getPreferenze();

Preferenze.setVisible(true);

}

}

});

}

return Salva_btn;

}

/**

* This method initializes jContentPane

*

* @return javax.swing.JPanel

*/

private JPanel getJContentPane() {

if (PrefContentPane == null) {

try {

GridBagConstraints gridBagConstraints32 = new GridBagConstraints();

gridBagConstraints32.gridx = 0;

gridBagConstraints32.gridy = 5;

Player_lbl = new JLabel();

Player_lbl.setText("Nome giocatore");

Stile_lbl = new JLabel();

Stile_lbl.setText("Stile di gioco");

N_lbl = new JLabel();

N_lbl.setText("Numero di tipi di pedine");

H_lbl = new JLabel();

H_lbl.setText("Altezza griglia");

L_lbl = new JLabel();

L_lbl.setText("Larghezza griglia");

GridBagConstraints gridBagConstraints41 = new GridBagConstraints();

gridBagConstraints41.insets = new Insets(35, 10, 2, 10);

gridBagConstraints41.fill = GridBagConstraints.NONE;

gridBagConstraints41.gridy = 0;

gridBagConstraints41.weightx = 1.0;

gridBagConstraints41.anchor = GridBagConstraints.SOUTH;

gridBagConstraints41.gridx = 1;

gridBagConstraints41.ipadx = 90;

GridBagConstraints gridBagConstraints31 = new GridBagConstraints();

gridBagConstraints31.insets = new Insets(5, 10, 5, 10);

gridBagConstraints31.gridx = 0;

gridBagConstraints31.fill = GridBagConstraints.HORIZONTAL;

gridBagConstraints31.anchor = GridBagConstraints.SOUTHWEST;

gridBagConstraints31.gridy = 0;

GridBagConstraints gridBagConstraints6 = new GridBagConstraints();

gridBagConstraints6.fill = GridBagConstraints.VERTICAL; // Generated

gridBagConstraints6.gridx = 1; // Generated

gridBagConstraints6.gridy = 4; // Generated

gridBagConstraints6.weightx = 1.0; // Generated

GridBagConstraints gridBagConstraints5 = new GridBagConstraints();

gridBagConstraints5.gridx = 1; // Generated

gridBagConstraints5.anchor = GridBagConstraints.EAST; // Generated

gridBagConstraints5.ipadx = 0; // Generated

gridBagConstraints5.insets = new Insets(15, 0, 35, 20); // Generated

gridBagConstraints5.fill = GridBagConstraints.NONE; // Generated

gridBagConstraints5.gridy = 7; // Generated

GridBagConstraints gridBagConstraints4 = new GridBagConstraints();

gridBagConstraints4.gridx = 0; // Generated

gridBagConstraints4.anchor = GridBagConstraints.WEST; // Generated

gridBagConstraints4.insets = new Insets(5, 10, 5, 10); // Generated

gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL; // Generated

gridBagConstraints4.gridy = 4; // Generated

GridBagConstraints gridBagConstraints3 = new GridBagConstraints();

gridBagConstraints3.fill = GridBagConstraints.NONE; // Generated

gridBagConstraints3.gridy = 3; // Generated

gridBagConstraints3.weightx = 1.0; // Generated

gridBagConstraints3.insets = new Insets(2, 10, 2, 10); // Generated

gridBagConstraints3.ipadx = 90; // Generated

gridBagConstraints3.anchor = GridBagConstraints.CENTER; // Generated

gridBagConstraints3.gridx = 1; // Generated

GridBagConstraints gridBagConstraints21 = new GridBagConstraints();

gridBagConstraints21.gridx = 0; // Generated

gridBagConstraints21.anchor = GridBagConstraints.WEST; // Generated

gridBagConstraints21.insets = new Insets(5, 10, 5, 10); // Generated

gridBagConstraints21.fill = GridBagConstraints.BOTH; // Generated

gridBagConstraints21.gridy = 3; // Generated

GridBagConstraints gridBagConstraints11 = new GridBagConstraints();

gridBagConstraints11.fill = GridBagConstraints.NONE; // Generated

gridBagConstraints11.gridy = 2; // Generated

gridBagConstraints11.weightx = 1.0; // Generated

gridBagConstraints11.insets = new Insets(2, 10, 2, 10); // Generated

gridBagConstraints11.ipadx = 90; // Generated

gridBagConstraints11.anchor = GridBagConstraints.CENTER; // Generated

gridBagConstraints11.gridx = 1; // Generated

GridBagConstraints gridBagConstraints2 = new GridBagConstraints();

gridBagConstraints2.gridx = 0; // Generated

gridBagConstraints2.insets = new Insets(5, 10, 5, 10); // Generated

gridBagConstraints2.fill = GridBagConstraints.BOTH; // Generated

gridBagConstraints2.gridy = 2; // Generated

GridBagConstraints gridBagConstraints1 = new GridBagConstraints();

gridBagConstraints1.fill = GridBagConstraints.NONE; // Generated

gridBagConstraints1.gridy = 1; // Generated

gridBagConstraints1.weightx = 1.0; // Generated

gridBagConstraints1.gridheight = 1; // Generated

gridBagConstraints1.insets = new Insets(2, 10, 2, 10); // Generated

gridBagConstraints1.ipadx = 90; // Generated

gridBagConstraints1.anchor = GridBagConstraints.SOUTH; // Generated

gridBagConstraints1.gridx = 1; // Generated

GridBagConstraints gridBagConstraints = new GridBagConstraints();

gridBagConstraints.gridx = 0; // Generated

gridBagConstraints.anchor = GridBagConstraints.SOUTH; // Generated

gridBagConstraints.gridheight = 1; // Generated

gridBagConstraints.ipadx = 0; // Generated

gridBagConstraints.insets = new Insets(0, 10, 5, 10); // Generated

gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; // Generated

gridBagConstraints.ipady = 0; // Generated

gridBagConstraints.gridwidth = 1; // Generated

gridBagConstraints.gridy = 1; // Generated

PrefContentPane = new JPanel();

PrefContentPane.setLayout(new GridBagLayout()); // Generated

PrefContentPane.add(L_lbl, gridBagConstraints);

PrefContentPane.add(getL_txt(), gridBagConstraints1);

PrefContentPane.add(H_lbl, gridBagConstraints2);

PrefContentPane.add(getH_txt(), gridBagConstraints11);

PrefContentPane.add(N_lbl, gridBagConstraints21);

PrefContentPane.add(getN_txt(), gridBagConstraints3);

PrefContentPane.add(Stile_lbl, gridBagConstraints4);

PrefContentPane.add(getSalva_btn(), gridBagConstraints5);

PrefContentPane.add(getStile_cbox(), gridBagConstraints6);

PrefContentPane.add(Player_lbl, gridBagConstraints31);

PrefContentPane.add(getPlayer_txt(), gridBagConstraints41);

PrefContentPane.add(getNewGameAfterWinCB(),

gridBagConstraints32);

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return PrefContentPane;

}

/**

* This method initializes Player_txt

*

* @return javax.swing.JTextField

*/

private JTextField getPlayer_txt() {

if (Player_txt == null) {

Player_txt = new JTextField("Anonimo");

}

return Player_txt;

}

/**

* This method initializes MenuTemi

*

* @return javax.swing.JMenu

*/

private JMenu getMenuTemi() {

if (MenuTemi == null) {

MenuTemi = new JMenu();

MenuTemi.setText("Cambia tema");

ButtonGroup group = new ButtonGroup();

MenuTemi.add(getStandard());

group.add(Standard);

MenuTemi.add(getFuturama());

group.add(Futurama);

MenuTemi.add(getKillBill());

group.add(KillBill);

}

return MenuTemi;

}

/**

* This method initializes Standard

*

* @return javax.swing.JMenuItem

*/

private JRadioButtonMenuItem getStandard() {

if (Standard == null) {

Standard = new JRadioButtonMenuItem("Base", true);

Standard.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

tema = "base";

if (game != null){

createLista();

printSurface();

}

}

});

}

return Standard;

}

/**

* This method initializes Futurama

*

* @return javax.swing.JMenuItem

*/

private JRadioButtonMenuItem getFuturama() {

if (Futurama == null) {

Futurama = new JRadioButtonMenuItem("Futurama");

Futurama.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

tema = "futurama";

if (game != null){

createLista();

printSurface();

}

}

});

}

return Futurama;

}

/**

* This method initializes NewGameAfterWinCB

*

* @return javax.swing.JCheckBox

*/

private JCheckBox getNewGameAfterWinCB() {

if (NewGameAfterWinCB == null) {

NewGameAfterWinCB = new JCheckBox(

"Inizia automaticamente un nuovo gioco alla fine della partita",

true);

}

return NewGameAfterWinCB;

}

/**

* This method initializes KillBill

*

* @return javax.swing.JRadioButtonMenuItem

*/

private JRadioButtonMenuItem getKillBill() {

if (KillBill == null) {

KillBill = new JRadioButtonMenuItem("Kill Bill");

KillBill.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

tema = "killbill";

if (game != null){

createLista();

printSurface();

}

}

});

}

return KillBill;

}

/**

* This method initializes MainPanel

*

* @return javax.swing.JPanel

*/

private JPanel getMainPanel() {

if (MainPanel == null) {

try {

StatusBarLabel = new JLabel();

StatusBarLabel.setText("Avvia un nuovo gioco!"); // Generated

MainPanel = new JPanel();

MainPanel.setLayout(new BorderLayout()); // Generated

MainPanel.add(StatusBarLabel, BorderLayout.SOUTH); // Generated

} catch (java.lang.Throwable e) {

// TODO: Something

}

}

return MainPanel;

}

public static void main(String[] args) {

try {

// Set System L&F

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {

e.printStackTrace();

}

new Swingui();

}

private Swingui() {

JFrame FinestraPrincipale = getFinestraPrincipale();

FinestraPrincipale.setVisible(true);

SalvaMappa.setEnabled(false);

}

private void printSurface() {

ContentPanePrincipale = null;

ContentPanePrincipale = new JPanel();

LayoutGriglia = new GridLayout(game.getH(), game.getL());

ContentPanePrincipale.setLayout(LayoutGriglia);

makeMatrice();

MainPanel.add(ContentPanePrincipale, BorderLayout.CENTER);

ContentPanePrincipale

.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

int x = evt.getX() / 38;

int y = (game.getH() - evt.getY() / 38) - 1;

try {

game.move(x, y);

StatusBarLabel.setText("Punteggio attuale: "

+ game.getPlayerScore());

} catch (RuntimeException e) {

StatusBarLabel.setText(e.toString().split(": ")[1]);

}

printSurface();

if (game.isEnded()) {

StatusBarLabel

.setText("Nessuna mossa disponibile!");

if (game.getPlayerName().equals("Anonimo")

|| game.getPlayerName().equals("")) {

String in = JOptionPane.showInputDialog(

"Inserisci il tuo nome", "Anonimo");

if (in == null || in.equals(""))

in = "Anonimo";

game.setPlayerName(in);

JOptionPane.showMessageDialog(null,

"Complimenti, " + game.getPlayerName()

+ "! Il tuo punteggio ? "

+ game.getPlayerScore(),

"Grande!",

JOptionPane.INFORMATION_MESSAGE);

} else {

JOptionPane.showMessageDialog(null,

"Complimenti, " + game.getPlayerName()

+ "! Il tuo punteggio ? "

+ game.getPlayerScore(),

"Grande!",

JOptionPane.INFORMATION_MESSAGE);

}

try {

if (NewGameAfterWinCB.isSelected()){

flag=true;

newGame();

}

else

ContentPanePrincipale.setVisible(false);

} catch (NullPointerException exptz) {

flag=true;

newGame();

}

}

}

});

FinestraPrincipale.pack();

}

private void newGame() {

try {

l = Integer.parseInt(L_txt.getText());

h = Integer.parseInt(H_txt.getText());

n = Integer.parseInt(N_txt.getText());

style = Stile_cbox.getSelectedIndex();

player = Player_txt.getText();

} catch (Exception e) {

l = 15;

h = 10;

n = 3;

style = 0;

player = "Anonimo";

}

try {

game = new Game(l, h, n, style);

game.setPlayerName(player);

} catch (IndexOutOfBoundsException e) {

JOptionPane.showMessageDialog(null, e.toString().split(": ")[1],

"Aiaiai...", JOptionPane.ERROR_MESSAGE);

}

printSurface();

StatusBarLabel.setText("Punteggio attuale: " + game.getPlayerScore());

SalvaMappa.setEnabled(true);

}

private void makeMatrice() {

if (flag) {

createLista();

flag = false;

}

for (int y = game.getH() - 1; y >= 0; y--) {

for (int x = 0; x < game.getL(); x++) {

char type = game.getSurface()[x][y].getType();

imageURL = getClass().getResource(returnPath(type));

image = new ImageIcon(imageURL);

piece = new JLabel(image);

ContentPanePrincipale.add(piece);

}

}

}

private void createLista() {

listaTipi=new ArrayList<String>();

int i = 0;

if (n == 0)

n = 20;

for (int y = game.getH() - 1; y >= 0; y--) {

for (int x = 0; x < game.getL(); x++) {

if (i < n) {

if (game.getSurface()[x][y].getType() != '.') {

if (notInLista(game.getSurface()[x][y].getType())) {

int j = i + 1;

String type = game.getSurface()[x][y].getType()

+ " " + "images/" + tema + "/" + j + ".png";

listaTipi.add(type);

i++;

}

}

} else

break;

}

if (i > n)

break;

}

}

private boolean notInLista(char type) {

if (listaTipi == null)

return true;

for (int k = 0; k < listaTipi.size(); k++) {

if (type == listaTipi.get(k).split(" ")[0].charAt(0))

return false;

}

return true;

}

private String returnPath(char type) {

for (int k = 0; k < listaTipi.size(); k++) {

if (type == listaTipi.get(k).split(" ")[0].charAt(0)) {

String path = listaTipi.get(k).split(" ")[1];

return path;

}

}

return "images/empty.png";

}

}

Message was edited by:

JinKazama

On Mac this class work perfectly

JinKazamaa at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 3

Please use the formatting when posting code.

If it works on a mac, but not windows, then I would suspect that the problem you are having is in realation to double buffering (Quartz double buffers everything for you automatically)... BTW, I didn't even look at the code, so I could be way off the mark, but it's something to look into.

macrules2a at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 4
Sorry ..i tried to set all the jpanels to double buffer with this code:JPanel.setDoubleBuffered(true); but nothing changes... any other suggestions?
JinKazamaa at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 5

I glanced through the code, and it doesn't appear that you are doing any animation in it, so that's my suggestion blown out of the water.

I'd strongly suggest that you create an [url=http://mindprod.com/jgloss/sscce.html]SSCCE[/url] that demonstrates the problem so we can take a look for you, and please use code formatting when you are posting this example, as described here: http://forum.java.sun.com/help.jspa?sec=formatting

macrules2a at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 6

> I'd strongly suggest that you create an

> [url=http://mindprod.com/jgloss/sscce.html]SSCCE[/url]

> that demonstrates the problem so we can take a look

> for you

I have not understood what I should do. - _ -

I have sent a mail to your address: macrules2@hotmail.com for explanations.

Sorry

JinKazamaa at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 7
Well that's guaranteed that you won't be getting any help from me.
macrules2a at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 8
Why? I don't really understand . Oo
JinKazamaa at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 9
> Why? I don't really understand . OoBecause he's not your private contractor. Stick to the forum rules, create as short a test as possible (without the NetBeans generated ****) and use code tags.
kirillga at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 10
I have resolved alone. With a little of imagination I have found the solution.MainPanel.removeAll();MainPanel.add(ContentPanePrincipale, BorderLayout.CENTER);MainPanel.add(StatusBarLabel,BorderLayout.SOUTH);Thanks to everybody
JinKazamaa at 2007-7-12 9:41:06 > top of Java-index,Desktop,Core GUI APIs...