formatting in applets

I am developing an online quiz applet, although I do not have much experience with applets. I have developed the internal workings of the program, and am about to start on the GUI. I have a few questions before I get started, so that I don't make a total mess out of things:

1. I have the design worked out on paper, complete with pixel measurements. How do I tell the applet to position an image at a specific (x, y) coordinate? The same goes for buttons and labels.
2. I need a timer to clock the quiz, giving the user 10 minutes to complete it. I know that this must be done using threads, but how do I create one? The thread must count down ten minutes, and update a label with the remaining time.
3. Is there a simple way, once I've added a button to my applet to either remove it or hide it from the user? Something like button.remove( ) or button.setVisible(false)?

Those are my basic questions for now. Any help is greatly appreciated.


If you have enough memory, you won't have enough disk space.

Comments


  • : 1. I have the design worked out on paper, complete with pixel measurements. How do I tell the applet to position an image at a specific (x, y) coordinate? The same goes for buttons and labels.

    Jave uses layouts for positioning GUI elements like buttons, images, etc. The idea is to given min and max bounds for positioning and let the LayoutManager do the rest. The type of layout specifies the way of component placing. But you can set the layout to null, indicating that you position everything yourself. Start out with a JPanel and call setLayout(null). Then, for every component, call setLocation(x,y) to position.

    : 2. I need a timer to clock the quiz, giving the user 10 minutes to complete it. I know that this must be done using threads, but how do I create one? The thread must count down ten minutes, and update a label with the remaining time.

    You don't really need threads for this. Use the AWT class Timer, you can specify the amount of time to elapse before the timer notifies you with calling actionPerformed.

    : 3. Is there a simple way, once I've added a button to my applet to either remove it or hide it from the user? Something like button.remove( ) or button.setVisible(false)?

    setVisible(false) should work fine; but if you use a non-null layout manager, the components will probably be re-ordered. But since you're not, you should be fine.
  • :
    : : 1. I have the design worked out on paper, complete with pixel measurements. How do I tell the applet to position an image at a specific (x, y) coordinate? The same goes for buttons and labels.
    :
    : Jave uses layouts for positioning GUI elements like buttons, images, etc. The idea is to given min and max bounds for positioning and let the LayoutManager do the rest. The type of layout specifies the way of component placing. But you can set the layout to null, indicating that you position everything yourself. Start out with a JPanel and call setLayout(null). Then, for every component, call setLocation(x,y) to position.
    :
    : : 2. I need a timer to clock the quiz, giving the user 10 minutes to complete it. I know that this must be done using threads, but how do I create one? The thread must count down ten minutes, and update a label with the remaining time.
    :
    : You don't really need threads for this. Use the AWT class Timer, you can specify the amount of time to elapse before the timer notifies you with calling actionPerformed.
    :
    : : 3. Is there a simple way, once I've added a button to my applet to either remove it or hide it from the user? Something like button.remove( ) or button.setVisible(false)?
    :
    : setVisible(false) should work fine; but if you use a non-null layout manager, the components will probably be re-ordered. But since you're not, you should be fine.
    :

    Thanks for your help. When using a JPanel in an applet, I assume that I create my various buttons, images, and textfields, create a JPanel with layout set to null, and then set the (x,y) coordinates of each component. But how do I set the size of the JPanel, or is this done automatically based on how big I need the panel to be? Would you have a small example that I could look at, with say one or two components? Thanks for you help.



    If you have enough memory, you won't have enough disk space.

  • [b][red]This message was edited by the Illco at 2002-7-3 8:51:44[/red][/b][hr]
    If you're gonna use an applet you probably don't want Swing, so excuse me for using JPanel as an example. In AWT you use a whatever (Window?) instead. An example would be the following (using Swing again since I have more knowledge of that):
    [code]
    // A panel
    JPanel panel = new JPanel();

    // Two buttons
    JButton yesButton = new JButton( "Yes" );
    JButton noButton = new JButton( "No" );

    // Do some layouting
    panel.setLayout( null )
    yesButton.setLocation( 10, 10 );
    yesButton.setSize( 100, 25 );
    noButton.setLocation( 120, 10 );
    noButton.setSize( 100, 25 );

    // Perhaps size the panel
    panel.setSize( 130, 45 );
    [/code]
    In this example I sized the panel, but you should note that the final size will be determined by either the window size (in an application) or the size of your applet as defined in the HTML file.


    Oh, and of course you should add the components to the panel. And the panel to the applet. Duh...
  • [b][red]This message was edited by the Moderator at 2002-7-3 10:26:38[/red][/b][hr]
    So the code in my applet would look something like this, I guess:

    [code]
    public void init( )

    // A panel
    JPanel panel = new JPanel();

    // Two buttons
    JButton yesButton = new JButton( "Yes" );
    JButton noButton = new JButton( "No" );

    // Do some layouting
    panel.setLayout( null )

    panel.addComponent(yesButton);
    panel.addComponent(noButton);

    yesButton.setLocation( 10, 10 );
    yesButton.setSize( 100, 25 );
    noButton.setLocation( 120, 10 );
    noButton.setSize( 100, 25 );

    repaint;
    [/code]

    is there something else I have to do to add the panel to the applet, or is that enough?

    Two more questions:

    1. Is there a way to make the font on a button larger, or boldfaced, or a different color?

    2. What is the best image format for images that will contain text, lines, graphs, and geometrical diagrams?



    If you have enough memory, you won't have enough disk space.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories