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.
Re: Applets: Paint & Graphics
Check the Sun documentation,
Paint class.
Graphic class.
Re: Applets: Paint & Graphics
I'm looking for more of a tutorial, not a manual.
Re: Applets: Paint & Graphics
Documentation also come with examples. But not bulky ones.:o
Re: Applets: Paint & Graphics
If the Java documentation were as good as PHP's I'd be set but that's not really the case.:)
Anyway, I could still use a good example....
Re: Applets: Paint & Graphics
It's up to you. I believe that Java documentation is the best one in Java world.
Re: Applets: Paint & Graphics
Quote:
Originally Posted by eranga262154
It's up to you. I believe that Java documentation is the best one in Java world.
Unless you are a copy, paste type of developer
Re: Applets: Paint & Graphics
I've never copied code in my life... I just don't understand Java graphics and I can't find any examples that explain it from the stance of someone who has never used them.
I understand basic draw functions and whatnot I just don't understand things like the repaint() method and how to get it to paint what I want, when I want it to.
Re: Applets: Paint & Graphics
If that's the case, you might find this tutorial interesting.
Re: Applets: Paint & Graphics
Quote:
Originally Posted by ComputerJy
Unless you are a copy, paste type of developer
I Never do that. I used codes on my own practice.
Re: Applets: Paint & Graphics
Check this site out.
It has good tutorials on writing Java applets for Game Development.
Covers everything you need nicely...
http://www.javacooperation.gmxhome.d...lStartEng.html
Re: Applets: Paint & Graphics
Re: Applets: Paint & Graphics
Sorry to ask another question on this thread, but it's sort of related. Is there any way to get Java to draw gradients and/or with semi-transparent colors. This is easy to do in .NET, but I haven't found the APIs to do it in Java.
Re: Applets: Paint & Graphics
I don't know exact API for this. But for the gradients you can use, constructor Gradient() create gradient color with getGradient() method, and GradientPaint() use to fill the gradient color.
As far as I've remember, GradientPaint() syntax use as follows.
Code:
GradientPaint(start_x, start_y, start_color, end_x, end_x, end_color, true)
true define the repeatability of starting and ending colors.
Re: Applets: Paint & Graphics
Here is a working code sample (it's easier than you might think)
Code:
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
public class Test extends JFrame {
public Test() {
super("Test");
this.setSize(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
GradientPaint paint = new GradientPaint(0, 0, Color.BLUE, 300, 300, Color.BLACK);
((Graphics2D) g).setPaint(paint);
g.fillRect(0, 0, 300, 300);
}
public static void main(String[] args) {
new Test();
}
}
Re: Applets: Paint & Graphics
Quote:
Originally Posted by ComputerJy
Here is a working code sample (it's easier than you might think)
Is it for me. :o
On you code, my tip is correct. :) One question there. You don't use that boolean option in GradientPaint(), means that the default is true, or I'm wrong with parameters list?
On this machine I've work now haven't setup Java yet and I can't test your code.
Re: Applets: Paint & Graphics
Quote:
Originally Posted by eranga262154
Is it for me. :o
On you code, my tip is correct. :) One question there. You don't use that boolean option in GradientPaint(), means that the default is true, or I'm wrong with parameters list?
On this machine I've work now haven't setup Java yet and I can't test your code.
Just like any other boolean, if it's not set the default value is false.
And by the way, I've never said your code is wrong ;)
Re: Applets: Paint & Graphics
Quote:
Originally Posted by ComputerJy
And by the way, I've never said your code is wrong ;)
No way pal :p just checking that I've missing something