Q:

Java Applet - Changing the various Flowers using List Component

0

This Program is used to Demonstrate the various Flower images using List Component in Java.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

// Change the various images using List

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ima4 extends Applet implements ItemListener

{
List l;

Image i1,i2,i3,i4;

TextArea ta;

public void init()
{
i1 = getImage(getCodeBase(),"ro1.jpg");
i2 = getImage(getCodeBase(),"su1.jpg");
i3 = getImage(getCodeBase(),"lo1.jpg");

l=new List();
l.add("Rose");
l.add("SunFlower");
l.add("Lotus");
add(l);

l.addItemListener(this);

}

public void itemStateChanged(ItemEvent e)
{
repaint();
}

public void paint(Graphics g)
{
if(l.getSelectedItem()=="Rose")
{
g.drawImage(i1,80,100,this);
}

if(l.getSelectedItem()=="SunFlower")
{
g.drawImage(i2,80,100,this);
}

if(l.getSelectedItem()=="Lotus")
{
g.drawImage(i3,80,100,this);
}
} 
}

/* <body>
<applet code = "ima4.class" height = 350 width = 350>
</applet>
</body> */

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now