Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Red face how to make Frame resizable using button in applet.i m not using jframe.help me.

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    import java.awt.Frame;
    /*
    <applet code="FrameSizeChanger" width=500 height=500>
    </applet>
    */
    public class FrameSizeChanger extends Applet{


    Button btn1,btn2;
    Frame f;
    int width=80;
    int height=80;
    int x=50;
    int y=50;
    public void init(){



    f=new Frame();
    f.setBounds(x,y,width,height);
    f.setLayout(new GridLayout(2,1));
    btn1=new Button("Increment");
    btn2=new Button("Decrement");
    add(btn1);
    add(btn2);
    f.add(btn1);
    f.add(btn2);
    f.setVisible(true);

    btn1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){

    width=+10;
    height=+10;

    resize(width, height);
    // layout();
    //f.setLocation(x,y);
    //f.setSize(width,height);
    //f.pack();
    //f.setVisible(true);
    }
    });
    }


    }






    Actully i m want to create a simple awt applet program where whenver i click maximize n minimize button on frame ...frame window should be maximized n minimized.in this program i have only write code for maximize button actionlistener.how to do ..........i m stuck.....help me....Thanks in advace.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    What happens when you compile and execute the code? If there are errors, copy the full text and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    its not showing error,,,,,,,,,,,,,,maximize button work...but frame does not maximize.it goes small.

  4. #4
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    its not showing error...after clicking windows not getting maximized......otherwise its get smaller than default set in progam.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    Where does the code try to maximize the Frame? All I see is a call to resize() for the applet NOT the Frame.
    What are the values of width and height that the program uses with resize()? Add a println() statement that prints out their values so you can see what they are.
    Last edited by Norm; 09-21-2013 at 04:50 PM.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    import java.awt.Frame;
    /*
    <applet code="FrameSizeChanger" width=500 height=500>
    </applet>
    */
    public class FrameSizeChanger extends Applet{


    Button btn1,btn2;
    Frame f;
    int width=80;
    int height=80;
    int x=50;
    int y=50;
    public void init(){



    f=new Frame();
    f.setBounds(x,y,width,height);
    f.setLayout(new GridLayout(2,1));
    btn1=new Button("Increment");
    btn2=new Button("Decrement");
    add(btn1);
    add(btn2);
    f.add(btn1);
    f.add(btn2);
    f.setVisible(true);

    btn1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){

    width=+50;
    height=+50;


    f.resize(width, height);
    // layout();
    //f.setLocation(x,y);
    //f.setSize(width,height);
    //f.pack();
    //f.setVisible(true);
    }
    });
    }


    }


    /*at earlier post i have done mistake ...i used method resize of applet but i have to use f.resize(widht,height).but after calling resize method..its not showing perfect result.
    Last edited by codequicker@yahoo.com; 09-21-2013 at 05:10 PM.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    Please edit your post and wrap the code in code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    *to get highlighting and preserve formatting.


    .its not showing perfect result.
    Please explain.

    What are the values of width and height that the program uses with resize()? Add a println() statement that prints out their values so you can see what they are.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    i m newcomer to java....thanks for reminding me for printing value...finally i got my result.thankyou verymuch Norm.

    Norm,can u give me any idea about how to remember all classed n their methods.

    For all newcomers:-
    i m posting this code for any new programmer...so go through this ......n solve any problem if u find during your coding.


    Java Code:
    package abhiExample;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Frame;
    /*
    <applet code="FrameSizeChanger" width=500 height=500>
    </applet>
    */
    public class FrameSizeChanger extends Applet{
    
    	
    	Button btn1,btn2;
    	Frame f;
    	int width=80;
    	int height=80;
    	int x=50;
    	int y=50;
    	public void init(){
    		
    		
    		
    	    f=new Frame();
    		f.setBounds(x,y,width,height);
    		f.setLayout(new GridLayout(2,1));
    		btn1=new Button("Increment");
    		btn2=new Button("Decrement");
            add(btn1);
            add(btn2);
    		f.add(btn1);
    		f.add(btn2);
    		f.setVisible(true);
    		
    		btn1.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
    				
    				 height=f.getHeight();
    				 width=f.getWidth();
    				 System.out.println(height);
    				 System.out.println(width);
    				
    				 height=height+10;
    				 width=width+10;
    				
    				f.resize(width,height);
    				System.out.println(height);
    				System.out.println(width);
    				
    			}
    		});
    	
    	
    	btn2.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent ae){
    			height=f.getHeight();
    			width=f.getWidth();
    			
    			width=width-10;
    			height=height-10;
    			
    			f.resize(width, height);
               
    		  }
    	});
    	
     }
    }
    Last edited by codequicker@yahoo.com; 09-21-2013 at 05:43 PM.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    how to remember all classed n their methods.
    They are all documented here: Java Platform SE 7
    Java Code:
    width=+10;
    I think that you were trying to use the shortcuts but got the operators reversed:
    Java Code:
    width += 10;
    The print statements would be more readable if they included an id String:
    Java Code:
      System.out.println("resize width="+width +", heigth="+height);
    When only the values of the variables are printed (without labels) it can be hard to know what variables' values are shown.
    Last edited by Norm; 09-21-2013 at 05:41 PM.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    Thnks for your reply norm.....It might be possible that i will knock your door whenever i got stuck.i know u sure help me....
    Thanks for being here...

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    You're welcome.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    hello norm.......i m stuck again.

    In last program..i have added functionality to close frame when i click close (x)...but when i press close nothing going to happen.i have used windows Listener .......n used System.exit(0)...but this functionality is not working..Is there any way to enable System.exit(0) in eclipse.i had also done Policy udate.Here is my code.

    Java Code:
    package abhiExample;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Frame;
    /*
    <applet code="FrameSizeChanger" width=500 height=500>
    </applet>
    */
    public class FrameSizeChanger extends Applet{
    
    	
    	Button btn1,btn2;
    	Frame f;
    	Window win;
    	int width=80;
    	int height=80;
    	int x=50;
    	int y=50;
    	public void init(){
    		
    		
    		
    	    f=new Frame();
    		win=new Window(f);
    	    f.setBounds(x,y,width,height);
    		f.setLayout(new GridLayout(2,1));
    		btn1=new Button("Increment");
    		btn2=new Button("Decrement");
            add(btn1);
            add(btn2);
    		f.add(btn1);
    		f.add(btn2);
    		f.setVisible(true);
    		
    		win.addWindowListener(new WindowListener(){
    			public void windowOpened(WindowEvent we){
    				
    			}
    			public void windowActivated(WindowEvent we){
    				
    			}
    			public void windowIconified(WindowEvent we){
    				
    			}
    			public void windowClosing(WindowEvent we){
    				System.exit(0);
    			}
    			public void windowDeactivated(WindowEvent we){
    				
    			}
    			public void windowDeiconified(WindowEvent we){
    				
    			}
    			public void windowClose(WindowEvent we){
    				
    			}
    			public void windowClosed(WindowEvent we){
    				
    			}
    		});
    		
    		
    		
    		
    		btn1.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
    				
    				 height=f.getHeight();
    				 width=f.getWidth();
    				 //System.out.println("frame width="+width+" Height="+height);
    				 width+=10;
    				 height+=10;
    				// height=height+10;
    				// width=width+10;
    				//height=+10;
    				// width=+10;
    				f.resize(width,height);
    				System.out.println("resize width="+width+" Height="+height);
    				//System.out.println(width+","+height);
    				
    			}
    		});
    	
    	
    	btn2.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent ae){
    			height=f.getHeight();
    			width=f.getWidth();
    			
    			width=width-10;
    			height=height-10;
    			
    			f.resize(width, height);
               
    		  }
    	});
    	
     }
    }
    Last edited by Norm; 09-21-2013 at 07:59 PM. Reason: Added / in ending code tag

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    Applets can NOT use System.exit(). To get rid of an open Frame, call setVisible(false) and dispose()
    The browser is in charge of closing the html page that holds the applet.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    hey i m just looking for ebooks for learning swing...it will be good if u give me reference for any book
    And also i m having great confusion on thread....so can u plz give me best way to learn thread..thank you.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: how to make Frame resizable using button in applet.i m not using jframe.help me.

    Try Google. I don't have any book references.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: 12-07-2012, 06:50 PM
  2. Replies: 11
    Last Post: 11-14-2012, 07:48 PM
  3. Replies: 6
    Last Post: 03-11-2012, 04:44 PM
  4. Make java applet a button
    By hervey in forum New To Java
    Replies: 31
    Last Post: 10-30-2008, 05:44 AM

Posting Permissions

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