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)
My Application Code is below:
HTML Page is below:
public class MyApplet extends JApplet
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);
<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>
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.