Welcome to Dream.In.Code
Become a Java Expert!

Join 149,523 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,463 people online right now. Registration is fast and FREE... Join Now!




help in programming an applet that draws a diamond

 
Reply to this topicStart new topic

help in programming an applet that draws a diamond

zalami12
18 May, 2007 - 09:02 AM
Post #1

New D.I.C Head
*

Joined: 18 May, 2007
Posts: 2


My Contributions
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
User is offlineProfile CardPM
+Quote Post

spullen
RE: Help In Programming An Applet That Draws A Diamond
18 May, 2007 - 10:35 AM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
QUOTE(zalami12 @ 18 May, 2007 - 10:02 AM) *

hi people and programers!!

programmers are people too :-p

But yeah, you should think about tabbing the string using \t.
User is offlineProfile CardPM
+Quote Post

zalami12
RE: Help In Programming An Applet That Draws A Diamond
19 May, 2007 - 12:12 AM
Post #3

New D.I.C Head
*

Joined: 18 May, 2007
Posts: 2


My Contributions
QUOTE(spullen @ 18 May, 2007 - 11:35 AM) *

QUOTE(zalami12 @ 18 May, 2007 - 10:02 AM) *

hi people and programers!!

But yeah, you should think about tabbing the string using \t.


what do you mean...can you please explain or give me the trick code
User is offlineProfile CardPM
+Quote Post

spullen
RE: Help In Programming An Applet That Draws A Diamond
19 May, 2007 - 07:24 AM
Post #4

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
For instance if I did System.out.println("\t\t**"); it would move the ** over, so it's your task to figure out how to make certain one's tab over to the specific place where you want to them to go, so you need to make some sort of test.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:46PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month