hi people and programers!!
i have to program an applet that draws a diamond:
a *
a ***
a*****
a ***
a *
CODE
*
***
*****
***
*
please excuse the spacing...it has to be semetrical...
i programed two applets that can do two different forms of triangles:
CODE
Triangle
*
**
***
****
*****
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/**
* Runs an arbitrary loop, intro to while loops example
*/
public class Triangle extends Applet implements ActionListener
{
// sample awt objects
private TextArea display = new TextArea(10, 20);
private Button pressMe = new Button("Press me!");
private Label messages = new Label("I count from one to ten");
/**
* Add objects to the Applet
*/
public void init()
{
add(display);
add(pressMe);
add(messages);
// Causes button presses to be detected
pressMe.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
// run the loop
int count = 0;
messages.setText("drawing a triangle ");
while (count <= 8)
{
for ( int i=0; i< count; i++ )
{
display.append(" * ");
}
display.append(" * ");
count = count + 1;
display.append(" \n");
}
}
}
the second applet:
CODE
triangle 2
*
**
***
****
*****
****
***
**
*
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/**
* Runs an arbitrary loop, intro to while loops example
*/
public class Dim extends Applet implements ActionListener
{
// sample awt objects
private TextArea display = new TextArea(10, 20);
private Button pressMe = new Button("Press me!");
private Label messages = new Label("I can draw");
/**
* Add objects to the Applet
*/
public void init()
{
add(display);
add(pressMe);
add(messages);
pressMe.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
// run the loop
int count = 0;
while (count <= 5)
{
for ( int i=0; i< count; i++ )
{
display.append(" * ");
}
display.append(" * ");
count = count + 1;
display.append(" \n");
}
count = 5;
while (count >= 0)
{
for ( int i=0; i <count; i++ )
{
display.append(" * ");
}
display.append(" * ");
count = count - 1;
display.append(" \n");
}
}
}
if anyone can help me please do
thx a lot ill aprreciated more the faster i get the reply thx a lot another time
zaid alami
ps: you can email me at zalami12@gmail.com
This post has been edited by zalami12: 18 May, 2007 - 09:05 AM