小编sag*_*_dc的帖子

如何将JTextField和JCheckBox添加到ArrayList对象

我正在开发我的第一个GUI应用程序.

我有一个ArrayList父类Plant,我有四个子类.

我有一些JTextField信息和一些JCheckBox其他信息......

JTextFieldS的关系被转换成StringS和JCheckBoxs转换boolean.

我需要将所有这些组件添加到a ArrayList,然后显示Plants 的列表.

我怎样才能做到这一点?

例:

public class Flower extends Plant{

   private boolean thorns;
   private boolean smell;   

   public Flower(String name, String id, String color, boolean blnThorns, boolean blnSmell){
      super(name, id, color);
      thorns = blnThorns;
      smell = blnSmell;

   }

   public boolean isThorns(){

      return thorns;
   }

   public void setThorns(boolean blnThorns){
      thorns = blnThorns;  
   }

   public boolean isSmell(){

      return smell;
   } …
Run Code Online (Sandbox Code Playgroud)

java swing arraylist jcheckbox

1
推荐指数
1
解决办法
156
查看次数

标签 统计

arraylist ×1

java ×1

jcheckbox ×1

swing ×1