ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The first program should draw a single red triangle in the center of a 300 x 300 pixel Frame.
The second program should allow the user to pass the number of triangles to be drawn in a 300 x 300 pixel Frame as a command line argument. You are free to arrange the triangles in any way you like e.g. top down, left right, etc…
You'll have to realize that nobody here has the interest in doing an assignment for you. We WILL help you out if you are having specific problems making something work. So ask the right kind of questions and you'll get the answers you need.
Start writing the code and let us know what you are having problems with.
wel... ok. anyway thanx 4 comment
i am actually trying to do this right now,but i have no idea how to get started.
here is what i've done so far:as follows
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class DrawTriangles extends Applet
{
private Graphics g;
private Triangle redTriangle;
public void init ()
{
g = getGraphics ();
addMouseListener (new PointListener ());
} // method init
// PointListener is an inner class that listens for the mouse to be pressed.
class PointListener implements MouseListener
{
public void mousePressed (MouseEvent e)
{
int xval, yval;
xval = e.getX ();
yval = e.getY ();
redTriangle = new Triangle (Color.red, xval, yval);
redTriangle.drawTriangle (g);
} // mousePressed
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
public void mouseReleased (MouseEvent e) {}
public void mouseClicked (MouseEvent e) {}
} // class PointListener
} // class DrawTriangles
// Triangle draws triangles wherever the mouse has been pressed.
class Triangle
{
private int x, y;
private Polygon poly;
private Color color;
Triangle (Color c, int xPosition, int yPosition)
{
color = c;
x = xPosition;
y = yPosition;
} // constructor
/* drawTriangle creates two lists of points centered around x and y.
It then creates a new polygon and draws it. */
public void drawTriangle (Graphics g)
{
g.setColor (color);
int [] xList = {x-20, x, x+20};
int [] yList = {y, y-20, y};
poly = new Polygon (xList, yList, 3);
g.fillPolygon (poly);
} // method drawTriangle
} // class Triangle
public static void main(String args[]) {
Applet applet = new Triangle();
applet.setSize(300, 300);
applet.show();
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.