Computer Science Canada

Graphics Made Easy

Author:  Pman [ Wed Mar 12, 2014 10:53 pm ]
Post subject:  Graphics Made Easy

Turing Style Graphics
If there are some people that find graphics a little complicated, you can take a look at this simple java file and see how its done.
Or you can create an object and use it as basic Graphics. for your programs.

If you cannot tell from the name of the java file, I tried to make the style of graphics simple much like in turing.

Object
Below is a basic Object, The constructor is an integer Width, an integer Height, a String Location, and a boolean.
The width and Height are straight forward.
The location is for the window on the Screen, currently only have centre on screen or top-left.
The boolean if false says to draw the graphics as the cmethods are called.
Whereas if set to true you must manual call the update() method.
code:
TuringGraphics draw=new TuringGraphics(500,500,"center",false);

The Few that may need to be explained are:
setBackground - which sets the background Colour.
clear - which clears the screen.
update - if the booolean in the constructor was set to true this is used to update the graphics
text - just draws a string
getColour - is a method where you put in a string fro a name of a colour and it returns that colour which can be used to draw. only has a few colours
Added:
delay(time milli seconds)-allows you to delay your program
keyPressed() - retunrs a char for the key pressed if one is pressed within a time frame
keyTyped() - retunrs a char for the key Typed if one is typed within a time frame
keyReleased() - retunrs a char for the key Typed if one is released within a time frame
mouseClicked() - retunrs a int for button 1, 2 or 3 for the button clicked if one is clicked within a time frame
mouseClicked() - retunrs a int for button 1, 2 or 3 for the button clicked if one is clicked within a time frame
mouseClicked() - retunrs a int for button 1, 2 or 3 for the button clicked if one is clicked within a time frame
mousePressed() - retunrs a int for button 1, 2 or 3 for the button pressed if one is pressed within a time frame
mouseReleased() - retunrs a int for button 1, 2 or 3 for the button released if one is released within a time frame
mouseOnScreen() -a boolean returning true if mouse is in window false if not
mouseX() -returns current mouse position X relative to window
mouseY() -returns current mouse position Y relative to window
setLatency(int milliseconds) -allows you to set the window of time for keyboard and mosue clicks



Attached is the java file have fun Smile
And also the java doc. If you would like it commented pelase let me know
If you would like an example program just let me know Smile






Edit: New Updated Version. Includes Keys, mouse, and access to frame and panel. so you can now do anything.
Edit: Fixed a trailing html code

Author:  jesse kazomi [ Tue Jun 17, 2014 4:44 pm ]
Post subject:  Re: Graphics Made Easy

good job


: