codice:
package graphic;
import Project.Campionato;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import Project.Giocatore;
import javax.swing.JSplitPane;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class FinestraPartita extends JFrame {
/**
*
*/
private static final long serialVersionUID = 6555644770549918991L;
/* private JFrame frame;
private Palla ball;
private JLabel palla;*/
private JPanel panel_1;
/**
* Create the application.
*/
public FinestraPartita(Giocatore campo [][], final Campionato c) {
initialize(campo,c);
c.Partita(c.squadra, c.squadre[0],this,campo);
}
/**
* Initialize the contents of the frame.
*/
private void initialize(Giocatore campo [][],final Campionato c) {
this.setSize(700, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(new BorderLayout(0, 0));
JPanel panelScelte = new JPanel();
panel.add(panelScelte, BorderLayout.SOUTH);
panelScelte.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JButton btnStop = new JButton("Stop");
btnStop.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
//ferma la partita
c.setFerma(true);
}
});
panelScelte.add(btnStop);
JButton btnRilancia = new JButton("Rilancia");
btnRilancia.setEnabled(false);
panelScelte.add(btnRilancia);
JButton btnTira = new JButton("Tira");
panelScelte.add(btnTira);
JButton btnPassaggio = new JButton("Passaggio");
panelScelte.add(btnPassaggio);
JButton btnContrasto = new JButton("Contrasto");
panelScelte.add(btnContrasto);
JButton btnSostituzioni = new JButton("Sostituzioni");
panelScelte.add(btnSostituzioni);
JSplitPane splitPane = new JSplitPane();
panel.add(splitPane, BorderLayout.CENTER);
JLabel visualizzainfopartita = new JLabel("");
splitPane.setRightComponent(visualizzainfopartita);
panel_1 = new JPanel();
panel_1.setBackground(UIManager.getColor("OptionPane.questionDialog.border.background"));
splitPane.setLeftComponent(panel_1);
GridBagLayout gbl_panel_1 = new GridBagLayout();
gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
gbl_panel_1.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panel_1.setLayout(gbl_panel_1);
JLabel lblDifensore = new JLabel();
lblDifensore.setEnabled(false);
lblDifensore.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblDifensore = new GridBagConstraints();
gbc_lblDifensore.insets = new Insets(0, 0, 5, 5);
gbc_lblDifensore.gridx = 1;
gbc_lblDifensore.gridy = 1;
panel_1.add(lblDifensore, gbc_lblDifensore);
// ((MyJLabel) lblDifensore).setX(gbc_lblDifensore.gridx);
// ((MyJLabel) lblDifensore).setY(gbc_lblDifensore.gridy);
JLabel lblCentrocampista = new JLabel("");
lblCentrocampista.setEnabled(false);
lblCentrocampista.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblCentrocampista = new GridBagConstraints();
gbc_lblCentrocampista.insets = new Insets(0, 0, 5, 5);
gbc_lblCentrocampista.gridx = 3;
gbc_lblCentrocampista.gridy = 1;
panel_1.add(lblCentrocampista, gbc_lblCentrocampista);
JLabel lblCentrocampistaAvv = new JLabel("");
lblCentrocampistaAvv.setEnabled(false);
lblCentrocampistaAvv.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/pallaAvv.png")));
GridBagConstraints gbc_lblCentrocampistaAvv = new GridBagConstraints();
gbc_lblCentrocampistaAvv.insets = new Insets(0, 0, 5, 5);
gbc_lblCentrocampistaAvv.gridx = 4;
gbc_lblCentrocampistaAvv.gridy = 1;
panel_1.add(lblCentrocampistaAvv, gbc_lblCentrocampistaAvv);
JLabel lblDifensoreAvv = new JLabel("");
lblDifensoreAvv.setEnabled(false);
lblDifensoreAvv.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/pallaAvv.png")));
GridBagConstraints gbc_lblDifensoreAvv = new GridBagConstraints();
gbc_lblDifensoreAvv.insets = new Insets(0, 0, 5, 5);
gbc_lblDifensoreAvv.gridx = 6;
gbc_lblDifensoreAvv.gridy = 1;
panel_1.add(lblDifensoreAvv, gbc_lblDifensoreAvv);
JLabel lblPortiere = new JLabel("");
lblPortiere.setName("Portiere");
lblPortiere.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/portiere.gif")));
lblPortiere.setEnabled(false);
GridBagConstraints gbc_lblPortiere = new GridBagConstraints();
gbc_lblPortiere.insets = new Insets(0, 0, 5, 5);
gbc_lblPortiere.gridx = 0;
gbc_lblPortiere.gridy = 2;
panel_1.add(lblPortiere, gbc_lblPortiere);
JLabel lblDifensore_1 = new JLabel("");
lblDifensore_1.setEnabled(false);
lblDifensore_1.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblDifensore_1 = new GridBagConstraints();
gbc_lblDifensore_1.insets = new Insets(0, 0, 5, 5);
gbc_lblDifensore_1.gridx = 1;
gbc_lblDifensore_1.gridy = 2;
panel_1.add(lblDifensore_1, gbc_lblDifensore_1);
JLabel lblAttacAvv = new JLabel("");
lblAttacAvv.setEnabled(false);
lblAttacAvv.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/pallaAvv.png")));
GridBagConstraints gbc_lblAttacAvv = new GridBagConstraints();
gbc_lblAttacAvv.insets = new Insets(0, 0, 5, 5);
gbc_lblAttacAvv.gridx = 2;
gbc_lblAttacAvv.gridy = 2;
panel_1.add(lblAttacAvv, gbc_lblAttacAvv);
JLabel lblCentrocampista1 = new JLabel("");
lblCentrocampista1.setEnabled(false);
lblCentrocampista1.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblCentrocampista1 = new GridBagConstraints();
gbc_lblCentrocampista1.insets = new Insets(0, 0, 5, 5);
gbc_lblCentrocampista1.gridx = 3;
gbc_lblCentrocampista1.gridy = 2;
panel_1.add(lblCentrocampista1, gbc_lblCentrocampista1);
JLabel lblCentrocampistaAvv1 = new JLabel("");
lblCentrocampistaAvv1.setEnabled(false);
lblCentrocampistaAvv1.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/pallaAvv.png")));
GridBagConstraints gbc_lblCentrocampistaAvv1 = new GridBagConstraints();
gbc_lblCentrocampistaAvv1.insets = new Insets(0, 0, 5, 5);
gbc_lblCentrocampistaAvv1.gridx = 4;
gbc_lblCentrocampistaAvv1.gridy = 2;
panel_1.add(lblCentrocampistaAvv1, gbc_lblCentrocampistaAvv1);
JLabel lblAttaccante = new JLabel("");
lblAttaccante.setEnabled(false);
lblAttaccante.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblAttaccante = new GridBagConstraints();
gbc_lblAttaccante.insets = new Insets(0, 0, 5, 5);
gbc_lblAttaccante.gridx = 5;
gbc_lblAttaccante.gridy = 2;
panel_1.add(lblAttaccante, gbc_lblAttaccante);
JLabel lblDifensoreAvv1 = new JLabel("");
lblDifensoreAvv1.setEnabled(false);
lblDifensoreAvv1.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/pallaAvv.png")));
GridBagConstraints gbc_lblDifensoreAvv1 = new GridBagConstraints();
gbc_lblDifensoreAvv1.insets = new Insets(0, 0, 5, 5);
gbc_lblDifensoreAvv1.gridx = 6;
gbc_lblDifensoreAvv1.gridy = 2;
panel_1.add(lblDifensoreAvv1, gbc_lblDifensoreAvv1);
JLabel lblPortiereAvv = new JLabel("");
lblPortiereAvv.setEnabled(false);
lblPortiereAvv.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/portiere.gif")));
GridBagConstraints gbc_lblPortiereAvv = new GridBagConstraints();
gbc_lblPortiereAvv.insets = new Insets(0, 0, 5, 5);
gbc_lblPortiereAvv.gridx = 7;
gbc_lblPortiereAvv.gridy = 2;
panel_1.add(lblPortiereAvv, gbc_lblPortiereAvv);
JLabel lblDifensore_2 = new JLabel("");
lblDifensore_2.setEnabled(false);
lblDifensore_2.setIcon(new ImageIcon(FinestraPartita.class.getResource("/images/soccerSmall.png")));
GridBagConstraints gbc_lblDifensore_2 = new GridBagConstraints();
gbc_lblDifensore_2.insets = new Insets(0, 0, 5, 5);
gbc_lblDifensore_2.gridx = 1;
gbc_lblDifensore_2.gridy = 3;
panel_1.add(lblDifensore_2, gbc_lblDifensore_2);
.......... continua con la creazione delle JLabel
}
public JPanel getPanel(){
return panel_1;
}
}
qui invece il codice del campionato: