Welcome Guest [Log In] [Register]



Add Reply
Java Applets - Part 2 (Java)
Topic Started: Jun 3 2007, 12:47 PM (456 Views)
rig
1a5a6a4
Administrators
Wonder how to draw graphics, or to have something other then text? This is how to do it...

We use 2 classes, java.applet.Applet, and java.awt.Paint. We need to use these classes, so lets

import them like this.

Quote:
 

import java.applet.Applet;
import java.awt.*;
//The asterik will let us also use other items in java.awt. Dont always use an asterik

for importing classes, as it takes up more resources, slowing things down.


Look at the difference from regular programs here
Quote:
 
public class name extends Applet
{
public void paint(Graphics page)
{


Graphics, is a special object for the paint class. The Graphics page part means

we are creating a Graphics object called page. You'll learn more about objects later.

The graphics object, page, has some of its own methods. Like the keyboard class,

it is what we call Abstract. We will also talk about that more later.

Here are some basic methods for you to use:

• drawRect(x,y,l,w)
• fillRect(x,y,l,w)
• drawOval(x,y,l,w)
• fillOval(x,y,l,w)
• drawString(str,x,y);
• setColor(Color) //Color.black Color.blue Color.red Color.green and so on
//You can also use this:

page.setColor(new Color(r,g,B));

You can also search through some of the java class libraries online to find out

more


With most drawing methods, you can replace draw with fill. Not all, but most.

Quote:
 

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

public class firstapp extends Applet{

public void paint(Graphics page) {
page.setColor(Color.red);
page.fillRect(0,0,250,250);
}
}

Posted Image
Posted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply


Theme designed by Sith of Outline