Applets: Paint & Graphics

This is a discussion on Applets: Paint & Graphics within the Java forums, part of the Application Development category; Can anyone link me to a GOOD tutorial for applets and the paint method and how graphics work all around? ...


Go Back   Scriptasy > Application Development > Java
120 Online Register Projects Products Members List Calendar Today's Posts

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-31-2007, 07:41 AM
Junior Member
 
Join Date: Oct 2007
Posts: 3
Applets: Paint & Graphics

Can anyone link me to a GOOD tutorial for applets and the paint method and how graphics work all around? I've searched and searched but can't find a site that's really explained how to use graphics to paint on the screen from the view of a person who's never used that function of Java before. I just need to get the basic idea of it down and I haven't been able to do that with the walk-throughs that I've found.
Reply With Quote
  #2 (permalink)  
Old 01-27-2008, 11:40 PM
Junior Member
 
Join Date: Jan 2008
Posts: 5
This questions are not related to JAVA.
__________________
موقع -برامج -وصلات
Reply With Quote
  #3 (permalink)  
Old 06-12-2010, 10:30 PM
Junior Member
 
Join Date: Jun 2010
Posts: 4
Applets involving graphics and animations usually look more exciting than applets that don't. Here is a basic overview of how to implement graphics in an applet.
1. To draw images, import the class Image. Type this at the top of your code (not in your class):
import java.awt.Image; Now, create an Image object. Here is the code for making an Image object. Instead of typing "getCodeBase()", you can also replace it with a URL. If your picture file is inside a folder, you can also type that folder with the name:
Image myImage = getImage(getCodeBase(), "FolderName\\Pic5.jpg");
To draw the image, use the drawImage method of Graphics. The arguments to the method should be, in order, the image object name, the x coordinate, the y coordinate, the width, the height, and "this". Here is the code snippet: g.drawImage(myImage, 300, 200, 60, 120, this); The image's top left corner will be at (300,200). Its width will be 60 pixels, and its height will be 120 pixels.
Ads by Google Java Graph Applet
Create, analyze, layout and print diagrams and graphs online.
yEd - Graph Editor
Java SCJP Questions
SCJP mock exam Easy to use interface
JavaQ | Sun certified java professional practice exam |Welcome
Graphics2D
In the majority of browsers the Graphics object that the paint method receives can be casted into Graphics2D that provides more advanced features:
Graphics2D g2d = (Grapics2D) g;
// Turn everything that we will paint by the angle of 45 degrees:
g2d.rotate(Math.PI/4);
Generated images.To show your generated images like Mandelbrot set, use the BufferedImage class:Graphics2D g2d = (Grapics2D) g;
// Create 40*50 buffered image
BufferedImage img = new BufferedImage(40, 50, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D imageGraphics = img.createGraphics();
// Paint something here using the given graphics object
imageGraphics.setColor(Color.BLUE);
imageGraphics.drawLine(5,5,10,10);
// Set individual pixels (red dot at 1,1):
int redRGB = Color.RED.getRGB();
img.setRGB(1,1, redRGB);
// Draw the image as in example above:
g.drawImage(img, 300, 200, 60, 120, this);
Painting the BufferedImage will likely to take much less time than preparing it, so think if it is not possible to remember the image, reusing the same one if nothing has changed since the paint method have been previously called.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:11 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
scriptasy girl by HitmanN

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
W33