java 获取下标

[复制链接]
查看11 | 回复2 | 2009-6-6 12:08:52 | 显示全部楼层 |阅读模式
import java.awt.*;
import java.awt.event.*;
public class usfo1 extends WindowAdapter implements WindowListener,ActionListener
{
Frame f;
Button[] but;
public usfo1()
{f=new Frame();
f.setLayout(null);
f.setSize(1024,768);
f.addWindowListener(this);
f.setBackground(new Color(0,0,0));
int k=0;
but=new Button[90];
for (int i=0;i<=8;i++)
{
for(int j=0;j<=9;j++)
{

but[k]=new Button(""+k);

but[k].setSize(50,50);

but[k].setLocation(j*50+10,i*50+35);

but[k].addActionListener(this);

f.add(but[k]);



k++;
}
}

f.setVisible(true);

}
public void actionPerformed(ActionEvent e)
{
//就是想获取but的下标
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public static void main (String[] args)
{
usfo1 k=new usfo1();


}
}

回复

使用道具 举报

千问 | 2009-6-6 12:08:52 | 显示全部楼层
package com.ajax.test;import java.awt.*;import java.awt.event.*;import javax.swing.JButton;public class Usfo1 extends WindowAdapter implements WindowListener,ActionListener { Frame f; Button[] but; public Usfo1() {f = new Frame();f.setLayout(null);f.setSize(1024, 768);f.addWindowListener...
回复

使用道具 举报

千问 | 2009-6-6 12:08:52 | 显示全部楼层
public void actionPerformed(ActionEvent e) {System.out.println(e.getActionCommand());//这样就输出了按钮的的值比如你点1就会输出1 } }...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行