File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes paint() and applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "paint() and applets" Watch "paint() and applets" New topic
Author

paint() and applets

Shashank Gokhale
Ranch Hand

Joined: Jan 07, 2003
Posts: 90
Hi,
When you draw something to the screen in a paint() method, you specify some coordinates. But then you have to include a height and width variable in your applet tag as well.
So how do you know how much the value of either the height or the width parameters should be in the applet tag? For example
import java.awt.Graphics;
import java.applet.Applet;
public class disp extends Applet
{
public void paint(Graphics g)
{
g.drawString("One a clock, two o clock, three a clock rock",10,40);
g.drawRect(1,1,15,80);
}
}
<html>
<head><title></title></head>
<body>
<applet code="paintit.class" height=??? width=""">
</applet>
</body>
</html>
How do i know what the numbers for height and width need to be at the very minimum so that the entire applet is displayed on the screen and not cut off because the applet might be too big to be displayed in the size of the rectangle specified by height and width?


May the force of the Java be in all of us !!!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
You want the height and width to be less than the parameters specified in the html page that calls your applet.
[ January 16, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Shashank Gokhale
Ranch Hand

Joined: Jan 07, 2003
Posts: 90
Marilyn,
So I guess what youre saying is that the rectangular area created on the screen by the height and the width specified in the java class has the same size and location as that created by the height and width attribute in an applet tag
am i right in assuming this?
Shashank Gokhale
Ranch Hand

Joined: Jan 07, 2003
Posts: 90
Another question, how can I know what the coordinates are that mark the four corners of my browser screen? That is, is it
(0,0) for the topleft
(0,700) for the topright
(600,0) for the bottomleft
(600,700) for the bottomright?
How do I find out this information? If I know this then I can display applets where on the screen I want to because I know what the coordinate ranges are, so is there a way to find this out?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to The Applets Forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
wood burning stoves
 
subject: paint() and applets
 
Similar Threads
help me out!
paint() and applets
passing parameter to applet
Sizing Swing object on a JApplet
applet and the html file in separate directory