Computer problems,Computer help
*AX SOFT>>>Programming & Design

How to code a java picture?


I need a code with the following shapes:

Rectangle, Circle, Oval, Half-Oval, Horizontal Line.

Can you show me a sample of how this was done? I need to do this for a class of mine but I have no idea how to code in Java. All I have learned so far is html, and my time is too limited. We are using the program jcreator to compile the projects. Thanks.

There are a number of ways to do this. The solution depends on if you're wanting to use AWT, Graphics2D, JFC Swing, or even a non-standard library.

The shortest number of code lines would be using the AWT Graphics context but superior results are achieved via Graphics2D. We'll assume an AWT applet below:

import java.awt.*;
import java.applet.*;
public class graphicsApplet extends Applet {
public void paint(Graphics g) {
g.setColor(Color.black);
g.drawRect(92, 13, 20, 76); // draw Rectangle
g.drawOval(100,100,40,40); // draw Circle
g.drawOval(100,100,30,20); // draw Oval
g.drawArc(30,140,40,20,0,180); // draw Half-Oval
g.drawLine(23, 20, 66, 20); // draw Horizontal Line
} }

Play around with the first two x/y numbers in each "draw" to position the shapes where you'd want them. I simply made up some coordinates and can only guess how you'd want these displayed (e.g. size, order, etc.).

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • I can't edit my freewebs site!?

    Need to know how you are saving it. Are you using the FreeWebs online Visual/Text Editor then clicking the Save icon or are you trying to save your page from your browser via the File, Save Page a...

  • Where i can creat my own web for free? :)?

    Setting up a Web site is very easy and if you want to do it for free just go to ...

  • How can I get the value inside an <option></option> tag on a select box using javascript?

    Use the DOM! :) <script type="text/javascript"> var sel = document.getElementById("MySelectBox") var optVal = sel.options[<position of option, base 0>].text &l...

  • Is there a service where i can create my own Im system?

    Yes, you could host your own Jabber instant messaging server (see ...

  • Align Text ?

    You may have whitespace appearing in your code or a line break of some kind. Really need to see the code you used. As a safety note, not a good idea to put personal information on a web page......

  • Whats wrong with this php code?

    Take out the # before $fp You need to escape those single quotes in the 'echo' at the end, also I don't know what the () is for.....try this: echo "your post was posted su...

  • How can I learn how to build wire frames?

    For anything you want to know about 'how to', just type the question into your Google slot - how to make wire frames : - how to make wireframes & schematics - Scifi-Meshes.com Hi...

  • How do I use footnotes on microsoft word?

    Word has a very good footnote system that will automatically maintain the numbering sequence no matter what you do to the footnotes. It will also do its darnedest to keep the footnotes on the page...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster