Results 1 to 2 of 2
  1. #1
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default resize applet window based on user input

    Good morning all,
    I have built and Applet that runs and it does run in the browser. My issue is getting the applet window to resize based on user input. So the objective is when the user opens the web page, it asks them for a radius and then when they input the radius, it prints out the diameter, circumference, area and draws the circle. Since the size of the applet is set in the html document, I am not sure how to dynamically change it so that the height and width are equal to the diameter of the circle? So in the case of the image below, the user inputs 400 as the radius which means the diameter is 800 and I am actually wanting the width of the applet to then be say 900 x 900 to allow for the text.

    Any suggestions as to how to accomplish this would be great. Any links that might point me in the correct direction would certainly be appreciated. This was a homework assignment and it already got graded. I got a passing grade because it was functional, but did not get full credit because it would not grow to allow the entire circle to show. (Like a dummy when I built it, I put in smaller numbers and totally spaced on the teacher putting in something like radius = 400)

    Working output:
    resize applet window based on user input-full-view.png

    Broken output:
    resize applet window based on user input-appletview.png

    My Application Code is below:
    Java Code:
    import java.awt.Graphics;
    import javax.swing.JApplet;
    import javax.swing.JOptionPane;
    import java.math.*;
    public class MyApplet extends JApplet
      float diameter;
      float circumference;
      float area;
      float myRad;
      public void init()
      String rad = JOptionPane.showInputDialog("Enter Radius as floating-point number");
      myRad = Float.parseFloat(rad);
      diameter = myRad * 2;
      circumference = (float) (2*Math.PI*myRad);
      area = (float) ((myRad * myRad)*Math.PI);
      public void paint( Graphics g)
        int diam = (int) diameter;
        g.drawString("You input the following radius: " + myRad, 25, 10);
        g.drawString("Diameter is: " + diameter, 25, 25);
        g.drawString("Circumeference is: " + circumference, 25, 40);
        g.drawString("Area is: " + area, 25, 55);
        g.drawOval(25, 65, diam, diam);
    HTML Page is below:
    Java Code:
       <TITLE>Applet HTML Page</TITLE>
    *** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***
    If you need to modify this HTML launcher file (e.g., to add applet parameters), 
    copy it to where your applet class is found in the SRC folder. If you do this, 
    the IDE will use it when you run or debug the applet.
    Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in 
    the Packaging page in the Project Properties dialog.
    For more information see the online help.
    <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
    <APPLET codebase="classes" code="MyApplet.class" width=350 height=200></APPLET>
    <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>

  2. #2
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default Re: resize applet window based on user input

    I just changed the height and width in the html document to 100% and it shows the entire page.

Similar Threads

  1. Displaying a square based on user's input
    By luke in forum New To Java
    Replies: 15
    Last Post: 07-14-2012, 09:43 AM
  2. Creating an object based on user input parameters
    By monkeyhead in forum New To Java
    Replies: 5
    Last Post: 11-14-2011, 11:59 PM
  3. How do I retrieve data based on user input?
    By tunali2 in forum New To Java
    Replies: 1
    Last Post: 04-03-2011, 02:40 PM
  4. Creating a number of objects based on user input.
    By Kevinius in forum New To Java
    Replies: 21
    Last Post: 04-03-2011, 08:53 AM
  5. Dynamic Create Object based on user's input?
    By diskhub in forum New To Java
    Replies: 2
    Last Post: 03-08-2011, 04:47 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