christmas tree
807607Nov 24 2006 — edited Nov 24 2006i am making a christmas tree in java from drawing a simple triangle and a square which should be linked together. I am doin it with two codes in textpad but am having troubles with the coordinates. my triangle comes out fine but behinds my buttons and i am having trouble drawing the square.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class christmastree extends Applet
{
Label label1, label2;
Button presents, tinsel, lights, star, decerations;
Tree1 mytree;
public void init()
{
label1 = new Label("This is a christmas tree");
label2 = new Label("If you wish to add decerations to christmas tree use the button below");
presents = new Button ("Button for getting presents");
tinsel = new Button ("Button for getting tinsel");
lights = new Button ("Button for getting lights");
star = new Button ("Button for getting star");
decerations = new Button ("Button for getting decerations");
mytree = new Tree1();
add(label1);
add(label2);
add(presents);
add(tinsel);
add(lights);
add(star);
add(decerations);
}
public void paint(Graphics graf)
{
mytree.drawtree(graf);
}
}// end of christmastree class
tree code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Tree1
{
public void drawtree(Graphics tree){
int[]xcorods = new int[]{100,150,200};
int[]ycorods = new int[]{125,75,125};
tree.drawPolygon(xcorods,ycorods,3);
int[]xcrods = new int[]{125,175,125,175};
int[]ycrods = new int[]{225,300,225,300};
tree.fillPolygon(xcrods,ycrods,4);
int[]xBasecorods = new int[]{125,175,175};
int[]yBasecorods = new int[]{215,200,25};
tree.drawPolygon(xcrods,ycrods,3);
}
}
please note that i have only created and added buttons and i do not require code for them as i can do that myself. any help will be appreiceated thanks.