Draw Demonstration
This is a simple example of some of the many drawing methods of the graphics object. For further, more involved examples see our Graphics page.
The code of DrawApplet.pas
namespace draw; { Author: Michael McGuffin Converted to Oxygene for Java by Dharmesh Tailor } interface uses java.util, java.applet.*, java.awt; type DrawApplet = public class(Applet) public method init; override; method paint(g : Graphics); override; end; implementation method DrawApplet.init; begin setBackground(Color.black); end; method DrawApplet.paint(g : Graphics); begin g.setColor(Color.red); g.drawRect(10, 20, 100, 15); g.setColor(Color.pink); g.fillRect(240, 160, 40, 110); g.setColor(Color.blue); g.drawOval(50, 225, 100, 50); g.setColor(Color.orange); g.fillOval(225, 37, 50, 25); g.setColor(Color.yellow); g.drawArc(10, 110, 80, 80, 90, 180); g.setColor(Color.cyan); g.fillArc(140, 40, 120, 120, 90, 45); g.setColor(Color.magenta); g.fillArc(150, 150, 100, 100, 90, 90); g.setColor(Color.black); g.fillArc(160, 160, 80, 80, 90, 90); g.setColor(Color.green); g.drawString('Groovy!', 50, 150); end; end.
A minimal project file draw.oxygene
Execute the compiler by typing at the command prompt (with the current directory set to the location of this project file and the source file):
msbuild draw_applet.oxygene<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <PropertyGroup> <OutputType>Library</OutputType> </PropertyGroup> <ItemGroup> <Reference Include="rt.jar" /> </ItemGroup> <ItemGroup> <Compile Include="DrawApplet.pas" /> </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.targets" /> </Project>
Web page draw.html to run the applet
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Draw Demo</title> </head> <body> <center> <h3>Draw Demo</h2> <p>Java must be enabled.</p> <applet archive="draw.jar" code="draw/DrawApplet.class" width="300" height="300" /> </center> </body> </html>