How to finding an applets size, JAVA Programming

Finding an Applet's Size

When running inside a web browser the size of an applet is set through the height and width attributes and cannot be changed by the applet. Several applets require knowing their own size. After all you don't want to draw outside the lines.

Retrieving the applet size is straightforward with the getSize() method. java.applet.Applet inherits this method from java.awt.Component. getSize() returns a java.awt.Dimension object. A Dimension object has two public int fields, height and width. Below is a simple applet that prints its own dimensions.

import java.applet.*;
import java.awt.*;

public class SizeApplet extends Applet {

public void paint(Graphics g) {

Dimension appletSize = this.getSize();
int appletHeight = appletSize.height;
int appletWidth = appletSize.width;

g.drawString("This applet is " + appletHeight +
" pixels high by " + appletWidth + " pixels wide.",
15, appletHeight/2);


Remember how the applet's height is used to decide where to draw the text. You'll frequent needs to use the applet's dimensions to determine how to place objects on the page. The applet's width wasn't used because it made more sense to left justify the text rather than center it. In other programs you'll have occasion to use the applet width too.

Posted Date: 5/16/2013 6:25:15 AM | Location : United States

Related Discussions:- How to finding an applets size, Assignment Help, Ask Question on How to finding an applets size, Get Answer, Expert's Help, How to finding an applets size Discussions

Write discussion on How to finding an applets size
Your posts are moderated
Related Questions
What is the difference among session scope and request scope when saving formbean? Ans) When the scope is request, the values of formbean would be there for the current request.

JDBC stands for Java Database Connectivity: It is an API which gives easy connection to a wide range of databases. To connect to a database we have to load the appropriate dri

Question: (a) State and explain clearly FIVE new features of Actionscript 3.0 as compared to Actionscript 2.0. (b) Explain clearly the concept of events and events listen

You are required to write a program that is going to be used to store the student details of a particular school.  This school caters for students aged between 5 years to 15 years.

Depicts the typical communication between external users and the system. The emphasis is on what a machine does rather than how it works it. A use case is a summary of scenarios fo

Project Description: Overview I am seeking an Oracle ADF mobile app and web service to be created that takes a list of contacts stored on an Android mobile phone or tablet an

Write a program that prompts for two people’s birthdays (month and day), along with today’s month and day. The program should figure out how many days remain until each user’s birt

When wiring beans, if a bean element is embedded to a property tag directly, then that bean is said to the Inner Bean. The disadvantage of this bean is that it cannot be reused any

I'm seeking to hire someone to build me a program that can solve a php captcha. It should be a web service or script. You will write it in any language since i will execute i ca

What 'System.out.println()' signifies? 'System' is a predefined class. System class gives access to the system. 'out' is the output stream. 'println' is printin