java 在一个面板中从上到下添加组件_java 重新向容器添加组件时 怎么显示出来 主要代码如下。 都是在一个类里面的...

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();

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值