/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
JFrame og JLayeredPane
Fra : Dawn Hammer


Dato : 22-01-02 00:13

Hej
Jeg har et problem som jeg simpelthen ikke /kan/ løse... Jeg vil gerne
lave niveauer i min JFrame, men når jeg kører mit program får jeg en
JFrame med gråt indhold - eller, hvis jeg er heldig, grønt. Jeg har
prøvet snartsagt alle tips og tricks jeg har kunnet finde på Suns
hjemmeside - intet resultat... Er der nogen der kan hjælpe (kode
indsat nederst)?

Mvh.
Dawn
//-----------------------------------------------------
//GUI.java
//----------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GUI extends JFrame
{
private GUI_felt[] gui_f = new GUI_felt[40];
private JPanel[] jp1 = new JPanel[40], jp2 = new JPanel[40];
private JLayeredPane JLP;
private Spil s;
private JPanel pBraet, pHuse, pBrikker, pNord, pSyd, pVest, pOst,
pCenter, lastCenter = null,
Ost1, Ost2, Vest1, Vest2, Syd1, Syd2, Nord1, Nord2;


//--------------------------------------------------------------------
-----
//Sætter GUI'en op

//--------------------------------------------------------------------
-----
public GUI(String[] spillere)
{
super("Matador");

s = new Spil(spillere);

//Sætter lag 0 op
for (int i = 0; i <=39; i++)
{
if (((s.getFelt(i)).getType()).compareTo("grund") == 0)
gui_f[i] = new GUI_grund((Grund)s.getFelt(i));
else if(s.getFelt(i).getType().compareTo("bryggeri") == 0)
gui_f[i] = new GUI_bryggeri((Bryggeri)s.getFelt(i));
else if(s.getFelt(i).getType().compareTo("faerge") == 0)
gui_f[i] = new GUI_faerge((Faerge)s.getFelt(i));
else if(s.getFelt(i).getType().compareTo("ddb") == 0)
gui_f[i] = new GUI_ddb((DDB)s.getFelt(i));
else if(s.getFelt(i).getType().compareTo("skat") == 0)
gui_f[i] = new GUI_skat((Skat)s.getFelt(i));
else
gui_f[i] = new GUI_felt(s.getFelt(i));
}

for (int i = 0; i <=39;i++)
{
gui_f[i].addMouseListener(new mouseListener());
gui_f[i].setBackground(new Color(0,128,0));
}

pSyd = new JPanel(new GridLayout(1,11));
pSyd.setSize(462,42);
for (int i = 10; i >= 0;i--)
pSyd.add(gui_f[i]);

pVest = new JPanel(new GridLayout(9,1));
pVest.setSize(42,378);
for (int i = 19; i >= 11; i--)
pVest.add(gui_f[i]);

pNord = new JPanel(new GridLayout(1,11));
pNord.setSize(462,42);
for (int i = 20; i <= 30; i++)
pNord.add(gui_f[i]);

pOst = new JPanel(new GridLayout(9,1));
pOst.setSize(42,378);
for (int i = 31; i <= 39; i++)
pOst.add(gui_f[i]);

pCenter = new JPanel();
pCenter.setSize(378,378);
pCenter.setBackground(new Color(0,128,0));

pBraet = new JPanel(new BorderLayout());
pBraet.setSize(462,462);
pBraet.setVisible(true);
pBraet.setBackground(new Color(0,128,0));
pBraet.add(pSyd, BorderLayout.SOUTH);
pBraet.add(pVest, BorderLayout.WEST);
pBraet.add(pNord, BorderLayout.NORTH);
pBraet.add(pOst, BorderLayout.EAST);
pBraet.add(pCenter, BorderLayout.CENTER);

//Sætter lag 1 op
for (int i = 0; i <= 39;i++)
{
jp1[i] = new JPanel();
jp1[i].add(new JLabel(new ImageIcon("layer.gif")));
jp1[i].setSize(42,42);
}

Syd1 = new JPanel(new GridLayout(1,11));
Syd1.setSize(462,42);
for (int i = 10; i >= 0;i--)
pSyd.add(jp1[i]);

Vest1 = new JPanel(new GridLayout(9,1));
Vest1.setSize(42,378);
for (int i = 19; i >= 11; i--)
pVest.add(jp1[i]);

Nord1 = new JPanel(new GridLayout(1,11));
Nord1.setSize(462,42);
for (int i = 20; i <= 30; i++)
pNord.add(jp1[i]);

Ost1 = new JPanel(new GridLayout(9,1));
Ost1.setSize(42,378);
for (int i = 31; i <= 39; i++)
pOst.add(jp1[i]);

pHuse = new JPanel(new BorderLayout());
pHuse.setSize(new Dimension(500,500));
pHuse.setVisible(true);
pHuse.setBackground(new Color(0,128,0));
pHuse.add(Syd1, BorderLayout.SOUTH);
pHuse.add(Vest1, BorderLayout.WEST);
pHuse.add(Nord1, BorderLayout.NORTH);
pHuse.add(Ost1, BorderLayout.EAST);

//Sætter lag 2 op
jp2[0] = new JPanel();
jp2[0].setSize(42,42);
JLabel dimmer = new JLabel(new ImageIcon("spiller1.gif"));
dimmer.setSize(42,42);
jp2[0].add(dimmer);

for (int i = 1; i <= 39;i++)
{
jp2[i] = new JPanel();
jp2[i].add(new JLabel(new ImageIcon("layer.gif")));
}

Syd2 = new JPanel(new GridLayout(1,11));
Syd2.setSize(462,42);
for (int i = 10; i >= 0;i--)
pSyd.add(jp2[i]);

Vest2 = new JPanel(new GridLayout(9,1));
Vest2.setSize(42,378);
for (int i = 19; i >= 11; i--)
pVest.add(jp2[i]);

Nord2 = new JPanel(new GridLayout(1,11));
Nord2.setSize(462,42);
for (int i = 20; i <= 30; i++)
pNord.add(jp2[i]);

Ost2 = new JPanel(new GridLayout(9,1));
Ost2.setSize(42,378);
for (int i = 31; i <= 39; i++)
pOst.add(jp2[i]);

pBrikker = new JPanel(new BorderLayout());
pBrikker.setSize(new Dimension(462,462));
pBrikker.setVisible(true);
pBrikker.setBackground(new Color(0,128,0));
pBrikker.add(Syd1, BorderLayout.SOUTH);
pBrikker.add(Vest1, BorderLayout.WEST);
pBrikker.add(Nord1, BorderLayout.NORTH);
pBrikker.add(Ost1, BorderLayout.EAST);


JLP = new JLayeredPane();
JLP.setPreferredSize(new Dimension(462,462));
JLP.setVisible(true);
JLP.add(pBraet,new Integer(0));
JLP.add(pHuse, new Integer(1));
JLP.add(pBrikker, new Integer(2));

Container contentPane = getContentPane();
contentPane.add(JLP);
contentPane.setLayout(new BorderLayout());
}


//--------------------------------------------------------------------
-----
//Indre klasse der håndterer mouseEvents

//--------------------------------------------------------------------
-----
private class mouseListener extends MouseAdapter
{

//--------------------------------------------------------------------
-
//Metode der svarer på et musseklik

//--------------------------------------------------------------------
-
public void mouseClicked(MouseEvent event)
{
if (lastCenter != null) pCenter.remove(lastCenter);
lastCenter =
((GUI_felt)event.getSource()).getCenterCard();
pCenter.add(lastCenter);
pCenter.updateUI();
}
}
} //GUI



 
 
Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste