Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Images in a LayerPane wont show up.  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three images that I want to show layered, one being a background, and the other two being text in front of the background. But when I executed it, nothing shows up. Then I test it by just adding the images without LayerPane, and they all showed up. What's the problem?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.lang.reflect.*;



public class Menu extends JFrame implements ActionListener
{
static int width = 570, height = 770;

String name;


JLabel startImageLabel;
JLabel csTitleLabel;
JLabel rpgLabel;

JButton startGame;
JButton options;
JButton credits;
JButton quit;

JPanel startGamePanel;
JPanel optionsPanel;
JPanel creditsPanel;
JPanel quitPanel;

JPanel titlePanel;
JPanel menuPanel;
JPanel titleFinalPanel;


ImageIcon startBackground;
ImageIcon csTitle;
ImageIcon rpgTitle;

Box menuBox;
Box startBox;
Box titleBox;

JLayeredPane titleLayer;



public Menu()
{

setTitle("Counter Strike RPG");


csTitle = new ImageIcon("cs.gif");
rpgTitle = new ImageIcon("rpg.gif");
startBackground = new ImageIcon("cs6.jpg");

csTitleLabel = new JLabel(csTitle, JLabel.CENTER);
csTitleLabel.setOpaque(true);

rpgLabel = new JLabel(rpgTitle, JLabel.CENTER);
rpgLabel.setOpaque(true);

startImageLabel = new JLabel(startBackground, JLabel.CENTER);
startImageLabel.setOpaque(true);


titleLayer = new JLayeredPane();
titleLayer.setPreferredSize( new Dimension(550, 350) );
titleLayer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
Point origion = new Point(0,0);
titleLayer.add(startImageLabel, new Integer(0));
titleLayer.add(csTitleLabel, new Integer(1));
titleLayer.add(rpgLabel, new Integer(2));



startGame = new JButton(" StartGame ");
options = new JButton(" Options ");
credits = new JButton(" Credits ");
quit = new JButton(" Quit ");

startGamePanel = new JPanel(); startGamePanel.add(startGame);
optionsPanel = new JPanel(); optionsPanel.add(options);
creditsPanel = new JPanel(); creditsPanel.add(credits);
quitPanel = new JPanel(); quitPanel.add(quit);

startGamePanel.setBorder(BorderFactory.createRaisedBevelBorder());
optionsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
creditsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
quitPanel.setBorder(BorderFactory.createRaisedBevelBorder());



menuPanel = new JPanel();
menuPanel.setLayout(
new BoxLayout( menuPanel, BoxLayout.Y_AXIS ) );
menuPanel.add(startGamePanel);
menuPanel.add(optionsPanel);
menuPanel.add(creditsPanel);
menuPanel.add(quitPanel);





menuBox = new Box( BoxLayout.X_AXIS );
menuBox.add( Box.createHorizontalGlue() );
menuBox.add( menuPanel );
menuBox.add( Box.createHorizontalGlue() );

startBox = new Box( BoxLayout.Y_AXIS );
startBox.add(titleLayer);
startBox.add(Box.createVerticalGlue() );
startBox.add(menuBox);
startBox.add(Box.createVerticalGlue() );


getContentPane().add(startBox);

startGame.setActionCommand("start");
options.setActionCommand("options");
credits.setActionCommand("credits");
quit.setActionCommand("quit");

startGame.addActionListener( this );
options.addActionListener( this );
credits.addActionListener( this );
quit.addActionListener( this );

Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setLocation(screenWidth / 4, 0);



}

public void actionPerformed(ActionEvent evt)
{
String getCommand;


if(evt.getSource().equals(startGame))
{
do
{
name = JOptionPane.showInputDialog("Enter Username");
}while(name.length()<1);

Teamselect ts = new Teamselect();
ts.setSize(570,770);
ts.setVisible(true);

}
repaint();

}





public static void main(String[] args)
{

Menu menu = new Menu();
menu.setSize(width, height);
menu.setVisible(true);



WindowQuitter wq = new WindowQuitter();
menu.addWindowListener(wq);


try
{

Thread.sleep(0000);
Runnable printImage = new Runnable()
{
public void run()
{

}
};

SwingUtilities.invokeAndWait(printImage);
}

catch(InterruptedException ix)
{
}
catch(InvocationTargetException x)
{
}

}

}

class WindowQuitter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!