Shadylookin
master debater
I'm trying to get this so that if you select circle it draws 20 random circles and if you select rectangle it draws 20 random rectangles.
this is what i have so far but it does not work.
any help would be appreciated
this is what i have so far but it does not work.
Code:
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.BorderLayout;
public class RandomDrawer extends JFrame{
private String names[]={"rectangle","circle"};
private JComboBox shapeBox;
public RandomDrawer(){
super("Random Drawer");
shapeBox = new JComboBox(names);
shapeBox.setMaximumRowCount(2);
add(shapeBox, BorderLayout.SOUTH);
add(new JPanel(), BorderLayout.CENTER);
ComboBoxEventHandler handler = new ComboBoxEventHandler();
shapeBox.addItemListener(handler);
}
private class ComboBoxEventHandler implements ItemListener{
public void itemStateChanged(ItemEvent event){
if(event.getSource()==names[0]){
int i;
for(i = 0;i<20;i++){
drawRectagle( Math.random()*400, Math.random()*400, Math.random()*400,
Math.random()*400);
}
}
else if(event.getSource()==names[1]){
int j;
for(j=0;j<20;j++){
drawOval(Math.random()*400, Math.random()*400, Math.random()*400,
Math.random()*400)
}
}
}
}
any help would be appreciated