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

    Default Can anyone tell me problem in this program ??

    pls someone tell me how to use the setBounds method...


    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()
    	{
    		this.setLayout(null);
    		
    		screen= new JLabel(new ImageIcon ("back.png"));
    		frame = new JFrame("BOW MASTER");
    		play=new JButton("PLAY");
    		quit= new JButton("QUIT");
    		
    	//	frame.setBounds(0, 0, 534, 329);
    		play.setBounds(50, 40, 20, 10);
    		quit.setBounds(10, 10, 50, 30);
    		
    		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);
    			
    		}
    		
    	}
    	
    }

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    You need to tell us a bit more about your program so we can help you.

    What are your expected results?
    What are the actual results?
    Are there any errors thrown? If so, show us the full stack trace.

    By the looks of it you are setting the bounds and then setting the size, which you shouldnt do as the bounds dictate the size.

    You may want to look here for some more information about JFrame

    Berkeleybross

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    Look at the setLocation() method.

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

    Default

    You should read the Sun Swing tutorials layout section since you really don't want to use setBounds but rather setPreferredSize(...) for some components and use the layout managers for most of your layout needs. Also, please don't double post questions. I've locked your other thread.

Similar Threads

  1. what is the problem in this program ?????
    By sahildave1991 in forum AWT / Swing
    Replies: 1
    Last Post: 06-29-2010, 01:36 PM
  2. Problem in Program
    By Abbinormal in forum New To Java
    Replies: 9
    Last Post: 01-08-2010, 03:38 AM
  3. Problem with the below program
    By srikanthnambu in forum Java 2D
    Replies: 1
    Last Post: 05-20-2009, 05:43 PM
  4. Program problem
    By arindamchkrbrty in forum New To Java
    Replies: 8
    Last Post: 03-10-2009, 04:58 AM
  5. program problem
    By amith in forum AWT / Swing
    Replies: 12
    Last Post: 05-16-2008, 08:07 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
  •