# Thread: resize applet window based on user input

1. Member
Join Date
Jan 2013
Location
Texas
Posts
45
Rep Power
0

## 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:

Broken output:

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;

public void init()
{
String rad = JOptionPane.showInputDialog("Enter Radius as floating-point number");

diameter = myRad * 2;
circumference = (float) (2*Math.PI*myRad);
}

public void paint( Graphics g)
{
super.paint(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:
<HTML>
<TITLE>Applet HTML Page</TITLE>
<BODY>

<!--
*** 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.

-->

<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

<P>
<APPLET codebase="classes" code="MyApplet.class" width=350 height=200></APPLET>
</P>

<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>

2. Member
Join Date
Jan 2013
Location
Texas
Posts
45
Rep Power
0

## 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.

#### Posting Permissions

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