PLEASE I NEED HELP ON THIS CODE.
I'M TRYING TO WRITE A CODE ON VENDING MACHINE. BUT FIRST OF ALL I NEED TO PUT PICTURES ON THE BUTTONS THAT I'M USING.
THE ThING IS I'M HAVING ERRORS WHEN USING THE SETICON. this is my code below....... (i jus want to put pictures on button before i proceed with the code.)
thanks
import java.awt.*;
import java.applet.*;
import java.awt.event. ActionListener;
import javax.swing.Ima geIcon;
import javax.swing.JTe xtPane;
public class vendmachine extends Applet
{
Color Armygreen = new Color(120, 100, 50);
Panel panel1 = new Panel();
Label header = new Label("WELCOME TO UJU'S VENDING MACHINE");
Panel panel2 = new Panel();
Button chip = new Button("Chips") ;
Button cookie = new Button("Coookie ");
Button walnut = new Button("Walnut" );
Button mintGum = new Button("MintGum ");
Button lifesaver = new Button("lifeSav er");
Button popcorn = new Button("Popcorn ");
Button nacho = new Button("Nacho") ;
Button mandm = new Button("M&M");
Button mixednut = new Button("mixed Nut");
Panel panel3 = new Panel();
JTextPane mytextArea = new JTextPane();
Panel panel4 = new Panel();
Panel panel5 = new Panel();
public void init()
{
setSize(400, 420);
setLayout(new BorderLayout()) ;
add(panel1);
add(panel1, BorderLayout.NO RTH);
panel1.add(head er);
panel1.setPrefe rredSize(new Dimension(400,5 0));
panel1.setBackg round(Color.GRA Y);
add(panel2);
add(panel2, BorderLayout.WE ST);
panel2.setPrefe rredSize(new Dimension(270 , 50));
panel2.add(chip );
panel2.add(cook ie);
panel2.add(waln ut);
panel2.add(mint Gum);
panel2.add(life saver);
panel2.add(popc orn);
panel2.add(nach o);
panel2.add(mand m);
panel2.add(mixe dnut);
panel2.setBackg round(Color.BLU E);
/* add(panel3);
add(panel3,Bord erLayout.CENTER );
// panel3.add(myte xtArea);
panel3.setPrefe rredSize(new Dimension(400,1 00));
// mytextArea.setB ackground(Color .PINK);
panel3.setBackg round(Color.CYA N);*/
add(panel4);
add(panel4,Bord erLayout.SOUTH) ;
panel4.setPrefe rredSize(new Dimension(400,1 00));
panel4.setBackg round(Color.RED );
add(panel5);
add(panel5,Bord erLayout.CENTER );
panel5.setPrefe rredSize(new Dimension(400,1 00));
panel5.setBackg round(Color.GRE EN);
}
public void paint(Graphics g)
{
//Image chips;
//Image mintGum, nachos, cookies, lifeSaver, MandM,walnut, popcorn,mixedNu t;
chip.SetIcon(ne w ImageIcon("chip s1.gif"));
mintGum.SetIcon (new ImageIcon("mint Gum.gif"));
nacho.SetIcon(n ew ImageIcon("nach os.gif"));
cookie.SetIcon( new ImageIcon("cook ies.gif"));
lifesaver.SetIc on(new ImageIcon("life saver.gif"));
mandm.SetIcon(n ew ImageIcon("m_m. gif"));
walnut.SetIcon( new ImageIcon("waln ut.gif"));
popcorn.SetIcon (new ImageIcon("popc orn.gif"));
mixednut.SetIco n(new ImageIcon("mixf ruit.gif"));
// g.drawImage(chi ps, 20, 20, this);
}
}
I'M TRYING TO WRITE A CODE ON VENDING MACHINE. BUT FIRST OF ALL I NEED TO PUT PICTURES ON THE BUTTONS THAT I'M USING.
THE ThING IS I'M HAVING ERRORS WHEN USING THE SETICON. this is my code below....... (i jus want to put pictures on button before i proceed with the code.)
thanks
import java.awt.*;
import java.applet.*;
import java.awt.event. ActionListener;
import javax.swing.Ima geIcon;
import javax.swing.JTe xtPane;
public class vendmachine extends Applet
{
Color Armygreen = new Color(120, 100, 50);
Panel panel1 = new Panel();
Label header = new Label("WELCOME TO UJU'S VENDING MACHINE");
Panel panel2 = new Panel();
Button chip = new Button("Chips") ;
Button cookie = new Button("Coookie ");
Button walnut = new Button("Walnut" );
Button mintGum = new Button("MintGum ");
Button lifesaver = new Button("lifeSav er");
Button popcorn = new Button("Popcorn ");
Button nacho = new Button("Nacho") ;
Button mandm = new Button("M&M");
Button mixednut = new Button("mixed Nut");
Panel panel3 = new Panel();
JTextPane mytextArea = new JTextPane();
Panel panel4 = new Panel();
Panel panel5 = new Panel();
public void init()
{
setSize(400, 420);
setLayout(new BorderLayout()) ;
add(panel1);
add(panel1, BorderLayout.NO RTH);
panel1.add(head er);
panel1.setPrefe rredSize(new Dimension(400,5 0));
panel1.setBackg round(Color.GRA Y);
add(panel2);
add(panel2, BorderLayout.WE ST);
panel2.setPrefe rredSize(new Dimension(270 , 50));
panel2.add(chip );
panel2.add(cook ie);
panel2.add(waln ut);
panel2.add(mint Gum);
panel2.add(life saver);
panel2.add(popc orn);
panel2.add(nach o);
panel2.add(mand m);
panel2.add(mixe dnut);
panel2.setBackg round(Color.BLU E);
/* add(panel3);
add(panel3,Bord erLayout.CENTER );
// panel3.add(myte xtArea);
panel3.setPrefe rredSize(new Dimension(400,1 00));
// mytextArea.setB ackground(Color .PINK);
panel3.setBackg round(Color.CYA N);*/
add(panel4);
add(panel4,Bord erLayout.SOUTH) ;
panel4.setPrefe rredSize(new Dimension(400,1 00));
panel4.setBackg round(Color.RED );
add(panel5);
add(panel5,Bord erLayout.CENTER );
panel5.setPrefe rredSize(new Dimension(400,1 00));
panel5.setBackg round(Color.GRE EN);
}
public void paint(Graphics g)
{
//Image chips;
//Image mintGum, nachos, cookies, lifeSaver, MandM,walnut, popcorn,mixedNu t;
chip.SetIcon(ne w ImageIcon("chip s1.gif"));
mintGum.SetIcon (new ImageIcon("mint Gum.gif"));
nacho.SetIcon(n ew ImageIcon("nach os.gif"));
cookie.SetIcon( new ImageIcon("cook ies.gif"));
lifesaver.SetIc on(new ImageIcon("life saver.gif"));
mandm.SetIcon(n ew ImageIcon("m_m. gif"));
walnut.SetIcon( new ImageIcon("waln ut.gif"));
popcorn.SetIcon (new ImageIcon("popc orn.gif"));
mixednut.SetIco n(new ImageIcon("mixf ruit.gif"));
// g.drawImage(chi ps, 20, 20, this);
}
}
Comment