**
//When an item from the list is selected, a checkbox along with the drawn graphics schould appear. but only the graphics appear. Help? *basic**
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Checkbox;
public class GetSelectedItemExample extends Applet implements ItemListener
{
Choice c;
CheckboxGroup g1 = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("Red");
public void init()
{
c = new Choice();
c.add("Select Option");
c.add("Primary Colors");
c.add("Secondary Colors");
c.add("Tertiary Colors");
add(c);
c.addItemListener(this);
add(checkBox1);
checkBox1.setVisible(false);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
public void paint(Graphics g)
{
String s1 = c.getSelectedItem();
if(s1 == "Primary Colors")
{
g.drawString("You have chosen:"+c.getSelectedItem(),100,100);
g.setColor(Color.RED);
g.drawRect(90,120,100,100);
g.fillRect(90,120,100,100);
add(checkBox1);
checkBox1.setVisible(true);
}
if(s1 == "Secondary Colors")
{
g.drawString("You have chosen:"+c.getSelectedItem(),100,100);
}
if(s1 == "Tertiary Colors")
{
g.drawString("You have chosen:"+c.getSelectedItem(),100,100);
}
}
}
SYvonneMendoza 0 Newbie Poster
SYvonneMendoza 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
SYvonneMendoza 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
SYvonneMendoza 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
SYvonneMendoza 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
SYvonneMendoza 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.