package untitled29;
import java.awt.*;
import java.awt.event.*;
public class li extends Frame implements ActionListener,ItemListener{
private Button b1;
private int[] number={1,2,3,4,5,6,7,8,9,10};
private Choice ch;
private int i,j;
private int index;
li(){
setLayout(new FlowLayout());
Button b1=new Button("关闭");
b1.addActionListener(this);
add(b1);
b1.setForeground(Color.black );
b1.setForeground(Color.red );
Choice ch=new Choice();
ch.addItemListener(this);
for(int i=0;i<number.length;i++)
ch.add(" "+number[i]);
add(ch);
setSize(350,200);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="关闭"){
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e){
// 获取 当前值
index = Integer.parseInt(((Choice)e.getSource()).getSelectedItem().trim());
repaint();
}
public void paint(Graphics g){
int x = 25;
int y=85;
g.setColor(Color.blue );
// 画圆,index 个
for (j = 0 ; j < index; j ++){
g.fillOval(x,y,20,20);
x+=30;
}
}
public static void main(String args[]){
(new li()).setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
public class li extends Frame implements ActionListener,ItemListener{
private Button b1;
private int[] number={1,2,3,4,5,6,7,8,9,10};
private Choice ch;
private int i,j;
private int index;
li(){
setLayout(new FlowLayout());
Button b1=new Button("关闭");
b1.addActionListener(this);
add(b1);
b1.setForeground(Color.black );
b1.setForeground(Color.red );
Choice ch=new Choice();
ch.addItemListener(this);
for(int i=0;i<number.length;i++)
ch.add(" "+number[i]);
add(ch);
setSize(350,200);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="关闭"){
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e){
// 获取 当前值
index = Integer.parseInt(((Choice)e.getSource()).getSelectedItem().trim());
repaint();
}
public void paint(Graphics g){
int x = 25;
int y=85;
g.setColor(Color.blue );
// 画圆,index 个
for (j = 0 ; j < index; j ++){
g.fillOval(x,y,20,20);
x+=30;
}
}
public static void main(String args[]){
(new li()).setVisible(true);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货