同学让我帮忙写这个,可我连JavaBean都不知怎么回事,求大牛帮助

解决方案 »

  1.   

    我理解是包括私有的类成员变量、公有的get、set方法、公有的构造方法的一个类
      

  2.   

    我看楼主还是仔细看看JavaBean的API,如果楼主要的话留下Email
      

  3.   


    package com.fendou.wyb;import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;class Color {
    HashMap<String, Integer> rgb = new HashMap<String, Integer>();public Color() {rgb.put(null, null);
    }public void init() {
    }public Color(String key, Integer value) {
    rgb.put(key, value);
    }public HashMap<String, Integer> getRgb() {
    return rgb;
    }public void setRgb(HashMap<String, Integer> rgb) {
    this.rgb = rgb;
    }
    }class Content {
    public Color color;public Content() {
    super();
    }public Content(Color color) {this.color = color;}public Color getColor() {
    return color;
    }public void setColor(Color color) {
    this.color = color;
    }
    }public class Detail {
    public ArrayList<Content> content;public Detail() {
    super();
    }public Detail(ArrayList<Content> content) {
    this.content = new ArrayList<Content>();
    for (int i = 0; i < content.size(); i++) {
    this.content.add(content.get(i));
    }
    }public static void main(String[] args) {
    Color color1 = new Color();
    Color color2 = new Color();
    Color color3 = new Color();
    Color color4 = new Color();
    Color color5 = new Color();
    Color color6 = new Color();
    Color color7 = new Color();
    Color color8 = new Color();
    Color color9 = new Color();
    color1.rgb.put("red", 11);
    color1.rgb.put("blue", 12);
    color1.rgb.put("green", 13);
    color2.rgb.put("red", 21);
    color2.rgb.put("blue", 22);
    color2.rgb.put("green", 23);
    color3.rgb.put("red", 31);
    color3.rgb.put("blue", 32);
    color3.rgb.put("green", 33);
    color4.rgb.put("red", 41);
    color4.rgb.put("blue", 42);
    color4.rgb.put("green", 43);
    color5.rgb.put("red", 51);
    color5.rgb.put("blue", 52);
    color5.rgb.put("green", 53);
    color6.rgb.put("red", 61);
    color6.rgb.put("blue", 62);
    color6.rgb.put("green", 63);
    color7.rgb.put("red", 71);
    color7.rgb.put("blue", 72);
    color7.rgb.put("green", 73);
    color8.rgb.put("red", 81);
    color8.rgb.put("blue", 82);
    color8.rgb.put("green", 83);
    color9.rgb.put("red", 91);
    color9.rgb.put("blue", 92);
    color9.rgb.put("green", 93);List<Content> contents = new ArrayList<Content>();contents.add(new Content(color1));
    contents.add(new Content(color2));
    contents.add(new Content(color3));
    contents.add(new Content(color4));
    contents.add(new Content(color5));
    contents.add(new Content(color6));
    contents.add(new Content(color7));
    contents.add(new Content(color8));
    contents.add(new Content(color9));for (int i = 0; i < contents.size(); i++) {
    System.out.print("the contents[" + i + "] red is "
    + contents.get(i).getColor().rgb.get("red"));
    System.out.print("\t the contents[" + i + "] blue is "
    + contents.get(i).getColor().rgb.get("blue"));
    System.out.println("\t the contents[" + i + "] green is "
    + contents.get(i).getColor().rgb.get("green"));
    }
    System.out.println("detail.content[7].color.rgb[\"red\"].value is "
    + contents.get(6).getColor().rgb.get("red"));
    }
    }