Results 1 to 11 of 11
  1. #1
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default Layout Manager of JApplet

    Hello to all expect Java developer, i quite new to java developer.

    My assignment is want to me code a JApplet without a layout manager which allow me to adjust the location of button or other components.

    I know how to create a JButton but not adjust location.

    Not only that, i also want to make ImageIcon to the applet.

    Please help me. I really need your help.


    Thanks for your help.

  2. #2
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    Another requirement is when applet application scale to full screen, all element inside the container should fit properly.

    What i want is JApplet ?

    Please provide some example and some explanation.

    Thanks for your help.

  3. #3
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    My assignment is want to me code a JApplet without a layout manager which allow me to adjust the location of button or other components.
    That may be possible by setting the layout into null....
    You may use the setBounds for adjusting...
    And have patience on setting its location...
    You may compile the program several times just to set the desired location within the container....
    Not only that, i also want to make ImageIcon to the applet.
    Try to browse the JLabel's documentation about on how to do that.... and also the other components.....
    Last edited by sukatoa; 06-20-2008 at 02:36 PM.
    freedom exists in the world of ideas

  4. #4
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JApplet;

    /**
    *
    * @author nicholas_tse
    */
    public class Test extends JApplet {

    /**
    * Initialization method that will be called after the applet is loaded
    * into the browser.
    */
    @Override
    public void init() {
    // TODO start asynchronous download of heavy resources

    Container content = getContentPane();
    //content.setBackground(Color.white);
    content.setLayout(null);

    content.add(new JButton("Button 1"));
    content.add(new JButton("Button 2"));
    content.add(new JButton("Button 3"));
    }

    // TODO overwrite start(), stop() and destroy() methods

    }
    ImageIcon any = new ImageIcon("D:\\Java\\SodaMachine\\cola_5.jpg");
    JLabel tenCents = new JLabel(any);
    content.add(tenCents);

    This one is ok.

    What is the difference between JPanel and Container ?

    I have try the folloing but doesn't get any reusly yet.

    Please provide some example to me.

    Thanks for your help.
    Last edited by Peter_APIIT; 06-21-2008 at 07:01 AM.

  5. #5
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    Any help please.

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    What is the difference between JPanel and Container ?
    JPanel's documentation

    Please provide some example to me.
    More detailed samples from the net.....
    freedom exists in the world of ideas

  7. #7
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    The JPanel documentation doesn't provide difference between JPanel and container ?

    I don't want to create null layout manager myself.
    I want some built in API.

    Thanks for your help.

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

    Default

    I don't want to create null layout manager myself.
    I want some built in API.
    This confuses me greatly. There is no "null layout manager" and no need to create one, as a null layout is essentially that -- no layout manager. Maybe I'm missing something here?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    What is the difference between JPanel and Container ?
    JPanel extends Container (one level removed) so JPanel is a Container that provides some more functionality. Reading the API doc should show you what JPanel provides that Container doesn't.

    You should become familiar with reading the API to help you use and understand java.

    If you have the JDK installed, there is a src.zip file in the folder with the JDK that has all the source for the java classes. Pick one of the simpler Layout managers and extract its source from the zip and look at that to see how a layout manager works.

  10. #10
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default null is a special value

    Quote Originally Posted by Fubarable View Post
    This confuses me greatly. There is no "null layout manager" and no need to create one, as a null layout is essentially that -- no layout manager. Maybe I'm missing something here?
    To get rid of somthing, we can set it to null. LayoutManagers are a special case, trying to set a layout manager to null will likely foul up other built-ins that are expecting it to be there. A JPanel (Java 2 Platform SE 5.0) is close to the base of the class for javax.swing.JFrame

    You can add a JPanel to a JFrame, just call add( .... ); with a constructed JPanel being passed into the add()

    And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JFrame.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  11. #11
    Peter_APIIT is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    Do you have any example code ?

    Please provide it here and let other benefits.

    Thanks for your help.

Similar Threads

  1. Database to JApplet
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 03-26-2008, 06:18 AM
  2. Another problem in JApplet :S
    By juju in forum Java Applets
    Replies: 2
    Last Post: 12-30-2007, 08:46 PM
  3. help with converting to JApplet
    By Simmy in forum AWT / Swing
    Replies: 2
    Last Post: 08-09-2007, 09:45 AM
  4. JApplet and html
    By paty in forum Java Applets
    Replies: 1
    Last Post: 08-02-2007, 06:41 PM
  5. MiG Layout Manager 2.4
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 06:11 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
  •