Make a Graphics2D class

I recently posted a topic on graphics 2D, and i got some awesome source code from lordkurt. Now i have a new problem.

I want to be able to make my own graphics class, that can be used from another program that i write. I want to be able to for instance do this "c.fillRect(x,y)". The one major problem that i am having is parameterising the method that i make. Can anyone help me out, i would be truly grateful.

P.S. lordkurt, if you want your stars from the previous topic, make any reply here. I ran out of duke points in the last topic

[558 byte] By [Roqueforta] at [2007-11-27 6:13:09]
# 1
Why on earth would you want to create your own Graphics2D class?
sabre150a at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 2

when i first started programming in ready we got a premade class called hsa. It had methods for drawing objects such as c.fillRect(x,y). I was making a really good ping pong game, but then i moved over to JGrasp which does not support the hsa console class. plus the hsa console was really bugged.

Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 3
the c.fillOval(x,y,10,10) method made it easy to program a ball that could move. All you had to do was assign an int variable x and y to the method and increment them, and the oval would move.
Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 4
So why not use Swing and then you just have to caste the Graphics presented as an argument in the paintComponent(Graphics g) method to a Graphics2D.
sabre150a at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 5

could you explain that a little more. all that i have used swing for is to make a GUI and to use the JOptionPane.

i don't know much about the graphics class. But my main problem was adding parameters to the method "public void paint(Graphics g)" , because i couldn't do this "public void paint(Graphics g ,int x, int y)"

Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 6
You need to go thought the Swing tutorial - http://java.sun.com/docs/books/tutorial/uiswing/ .
sabre150a at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 7
if anyone else would like to help? T_T
Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 8
sorry my bad thought you were not coming back
Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 9
Read the tutorial on [url= http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html]Custom Painting[/url]. You don't need to make your own Graphics2D class.
CaptainMorgan08a at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 10
i'm really set on making my own class, it would just make my main program that much shorter, and i would be able to use it in the future. so if anyone can help me with some source code?
Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 11

This is what i have made of the class and main program so far:

Class:

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Game

{

JFrame jf;

public void window(int x,int y)

{

jf = new JFrame();

jf.setSize (500, 235);

jf.setLocation(300,200);

jf.setForeground(Color.green);

jf.setTitle ("Roquefort's attempt - <(''<)");

jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

Container con = jf.getContentPane();

Color col = new Color (204,230,227);

con.setBackground(col);

jf.setVisible(true);

}

public void painter(Graphics g,int x,int y)

{

g.setColor(Color.red);

g.fillRect(x,y,50,50);

}

}

and the main program

public class UseGame

{

public static void main (String[]args)

{

Game g = new Game();

g.window(800, 600);

g.paint();

}

}

Roqueforta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...
# 12

sorry man, i cant help you with this, all the source codes that i gave you last time was not mine, i just found it 2 months ago when i'm starting to learn java.. i think you could do it to, just search and research.. maybe you could bump up with fine codes and information that you need...

good luck!!

lordkurta at 2007-7-12 17:21:14 > top of Java-index,Java Essentials,New To Java...