winJ(Strings){super(s);panel=newPanel();panel.setLayout(null);panel.setBackground(newColor(0,255,0));panel.setSize(900,800);text=newTextField(30);button1=newButton("getnu...
winJ(String s){
super(s);
panel=new Panel();
panel.setLayout(null);
panel.setBackground(new Color(0,255,0));
panel.setSize(900, 800);
text=new TextField(30);
button1=new Button("get number");
button2=new Button("show");
label=new Label("input a number");
setLayout(new FlowLayout());
//setLayout(null);
add(label);//label.setBounds(0,1,20,10);
add(text);//text.setBounds(20,1,20,10);
add(button1);//button1.setBounds(50,1,20,10);
add(button2);//button2.setBounds(80,1,20,10);
button1.addActionListener(this);
button2.addActionListener(this);
Button a=new Button("hai");
panel.add(a);
a.setBounds(20, 20,40, 40);
add(panel);
setBounds(5,5,1000,900);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
int g=0;
try{ num=Integer.parseInt(text.getText());
for(int i=0;i
g=i+1;
String s=String.valueOf(g);
la[i]=new Label(s);
la[i].setSize(20, 20);
man[i]=new shuZu(0);
}
}
catch(NumberFormatException event)
{
text.setText("please input the integer number");
}
}
if(e.getSource()==button2)
{
double angle=360/num;
for(int i=0;i
{
panel.add(la[i]);
la[i].setLocation((int)(350*Math.sin(i*angle)+500),(int)(350*Math.cos(i*angle)+500));
}
validate();
int a=jPro(man,num);
la[a].setForeground(new Color(255,0,0));
la[a].setSize(100,100);
la[a].setLocation(500,500);
this.add(panel);
validate();
}
展开