gpt4 book ai didi

Java - FlowPanel - 使用子项的父变量

转载 作者:行者123 更新时间:2023-11-30 09:52:43 25 4
gpt4 key购买 nike

public class PageIndex extends FlowPanel {
private PageHeader header;
private PageCenter center;
private PageFooter footer;
public PageIndex() {
this.header=new PageHeader();
this.add(header);

this.center=new PageCenter();
this.add(center);

this.footer=new PageFooter();
this.add(footer);
}
}

public class PageCenter extends FlowPanel {
private PageMenu menu;
private PageContent content;

public PageCenter() {
this.setStyle("center");

this.menu=new PageMenu(content);
this.add(menu);

this.content=new PageContent();
this.add(content);
}
}

public class PageMenu extends FlowPanel {
private PageContent content;
private PageMenuLogin login;
private PageMenuSearch search;
private PageMenuOffers offers;
private PageMenuStudents students;
private PageMenuShopping shopping;
private PageMenuEvents events;
public PageMenu (PageContent content) {
this.content=content;
this.login=new PageMenuLogin();
this.add(login);
this.search=new PageMenuSearch();
this.add(search);
this.offers=new PageMenuOffers();
this.add(offers);
this.students=new PageMenuStudents();
this.add(students);
this.shopping=new PageMenuShopping();
this.add(shopping);
this.events=new PageMenuEvents();
this.add(events);

// IF I WRITE THIS I GET AN org.apache.jasper.JasperException: java.lang.NullPointerException
this.content.daghine();
}
}

我需要管理内容实例,但不可见。抱歉,我有点生疏:)

最佳答案

您需要如何管理变量?你在对象内部,它应该允许你做任何你需要的事情。如果您需要访问父对象,请执行以下操作:

public class PageIndex extends FlowPanel {
protected final PageContent content;
...

public PageIndex() {
content = new PageContent(this);
this.add(content);
...
}

public PageContent getContent() {
return this.content;
}
}

public class PageContent extends FlowPanel {
protected final PageIndex index;

public PageContent(PageIndex index) {
this.index = index;
}

public PageIndex getIndex() {
return this.index;
}

public void exampleFunction() {
createLabel().setLabel("HOLAAA").setStyle("content_title");
}
}

public class PageMenuLogin extends FlowPanel {
protected final PageIndex index;

public PageContent(PageIndex index) {
this.index = index;
index.getContent().exampleFunction();
}

public PageIndex getIndex() {
return this.index;
}
}

关于Java - FlowPanel - 使用子项的父变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4146792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com