Java 在表的一列中添加按钮
我正在使用lwuit创建一个带有一些值和行侦听器的表。在j2me中。 我试图添加一个按钮和一个监听器,以便在表中有一个值,通过该值我可以实现一个行监听器。我使用了以下链接:。但当我将按钮添加到表中时,它会出现在表的末尾,因为表模型只接受对象作为其添加到表中的输入 通过使用此链接,我通过以下命令按按钮添加了按钮:Java 在表的一列中添加按钮,java,Java,我正在使用lwuit创建一个带有一些值和行侦听器的表。在j2me中。 我试图添加一个按钮和一个监听器,以便在表中有一个值,通过该值我可以实现一个行监听器。我使用了以下链接:。但当我将按钮添加到表中时,它会出现在表的末尾,因为表模型只接受对象作为其添加到表中的输入 通过使用此链接,我通过以下命令按按钮添加了按钮: container.addComponent(new Button("Details")); 我还尝试创建一个网格布局或表布局,并添加了带有数字行*列的按钮,但最后一个按钮的侦听器仍然
container.addComponent(new Button("Details"));
我还尝试创建一个网格布局或表布局,并添加了带有数字行*列的按钮,但最后一个按钮的侦听器仍然有效,其余按钮则无效。关于如何实现这一逻辑的任何想法。我的实际任务是向表中添加一个行单击侦听器。非常感谢您提供的任何概念或编码方面的帮助。意思是当我为一位朋友得到答案并与您分享时。他让我在网格或表格布局中添加按钮,按钮应该像2d数组一样添加,以便正确管理它们的侦听器
public class Midlet extends MIDlet implements ActionListener{
Form f;
Container c;
private int ROWS=100;
Button b[][];
private int COLUMNS=3;
public void startApp() {
Display.init(this);
f=new Form("grid with buttons");
c=new Container(new TableLayout(ROWS, COLUMNS));
b=new Button[ROWS][COLUMNS];
c.setScrollableX(true);
c.setScrollableY(true);
//c.setDraggable(true);
addElements();
//f.setScrollable(false);
f.setScrollVisible(true);
f.addComponent(c);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void addElements()
{
for(int i=0;i<ROWS;i++)
{
for(int j=0;j<COLUMNS;j++)
{
b[i][j]=new Button(i+" sdkljf "+j);
c.addComponent(b[i][j]);
b[i][j].addActionListener(this);
}
}
}
/**
*
* @param message message to be displayed
* @param title title of the alert
*/
public void showMsg(String message, String title)
{
final Dialog d=new Dialog(title);
d.setLayout(new GridLayout(1, 1));
Button b=new Button("Ok");
TextArea msg=new TextArea(message);
msg.setUIID(message);
msg.setEditable(false);
//dialogContainer.addComponent(msg);
//dialogContainer.addComponent(b);
d.addComponent(msg);
d.addComponent(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
d.dispose();
}
});
d.show();
}
public void actionPerformed(ActionEvent evt) {
for(int i=0;i<ROWS;i++)
{
for(int j=0;j<COLUMNS;j++)
{
if(b[i][j]==evt.getComponent())
{
showMsg(i+","+j, "sl;dkf;");
}
}
}
}
}
公共类Midlet扩展Midlet实现ActionListener{
表格f;
容器c;
私有整数行=100;
按钮b[][];
私有int列=3;
公开作废startApp(){
Display.init(this);
f=新表格(“带按钮的网格”);
c=新容器(新表格布局(行、列));
b=新按钮[行][列];
c、 setScrollableX(真);
c、 setScrollableY(真);
//c、 可设置的(真);
加法();
//f、 设置可滚动(假);
f、 setScrollVisible(真);
f、 添加组分(c);
f、 show();
}
公共无效pauseApp(){
}
公共应用程序(布尔无条件){
}
公共无效补遗()
{
对于(int i=0;i请提供代码。对于任何内容。最好是提供所有相关代码。但您没有提供任何代码。