Results 1 to 2 of 2
  1. #1
    sahildave1991 Guest

    Exclamation Creating menu screen for games

    i am making a game of bow and arrow and want to put the attached image as the main screen menu. On that i want to put two buttons play and quit.

    but i run this program there is a screen of size (534,329) and all over the frame there is a big play button.
    how can i get rid of that???

    is there a way that when i click the "play" written on the attached image, the second screen opens...because i dont want a button to spoil the screen.

    hope u understood my prob.

    Java Code:
    package Screens;
    
    import java.awt.event.*;
    import java.awt.*;
    
    import javax.swing.*;
    
    public class FirstScreen extends JApplet implements ActionListener
    {
    	Screen2 scr=new Screen2();
    	JLabel screen;
    	
    	JFrame frame;
    	JButton play,quit;
    	public void init()
    	{
    		setLayout(new FlowLayout());
    		
    		screen= new JLabel(new ImageIcon ("back.png"));
    		frame = new JFrame("BOW MASTER");
    		play=new JButton("PLAY");
    		quit= new JButton("QUIT");
    		
    		
    		frame.add(screen);
    		frame.add(quit);
    		frame.add(play);
    		
    		play.addActionListener(this);
    		quit.addActionListener(this);
    		
    		frame.setSize(534,329);
    		frame.setResizable(false);
    		frame.setVisible(true);
    		
    	}
    	
    	public void actionPerformed(ActionEvent e) 
    	{
    		if(e.getSource()==quit)
    		{
    			System.exit(0);
    		}
    		if(e.getSource()==play)
    		{
    			Screen2 scr=new Screen2();
    			scr.setVisible(true);
    			
    		}
    		
    	}
    	
    }
    Attached Thumbnails Attached Thumbnails Creating menu screen for games-back.jpg  

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    why are you using a JFrame within your JApplet rather than simply display the applet itself? Your JFrame uses BorderLayout by default, and so the last component added will cover the whole frame since all components are added (again by default) BorderLayout.CENTER. You should read the Sun Swing tutorials especially the layout section.

Similar Threads

  1. Replies: 2
    Last Post: 10-18-2009, 07:27 PM
  2. Replies: 0
    Last Post: 10-28-2008, 09:28 PM
  3. Help! Anagram Games
    By geeky123 in forum New To Java
    Replies: 6
    Last Post: 10-13-2008, 04:16 PM
  4. Creating a splash screen in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:29 PM
  5. Replies: 3
    Last Post: 12-15-2007, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •