我刚刚发现这真的很棒ColorFactory
我在第一个Swing项目中使用的类。它非常酷:我现在可以将我主要类中的命名颜色(例如“深红色”或“mediumaquamarine”)传递给createContentPane
Container
方法。我需要另一种方法来使用ColorFactory类吗?
代码:
frame.setContentPane(ContentPaneCreator.createContentPane("darkorange"));`
问:
我是否需要public final void setBackground(Color color, JPanel contentPane)
方法呢?是否可以在createContentPane()
方法内完成所有操作?感谢您的帮助。
import java.awt.Color;
import java.awt.Container;
import javax.swing.JPanel;
public final class ContentPaneCreator extends JPanel {
private static final long serialVersionUID = 1L;
public static Container createContentPane(String color) {
JPanel contentPane = new JPanel();
// awesome txt to Color conversions using the ColorFactory().getColor();
// written by The Lobo Project
new ContentPaneCreator().setBackground(
new ColorFactory().getColor(color), contentPane);
contentPane.setOpaque(true);
return contentPane;
}
public final void setBackground(Color color, JPanel contentPane) {
contentPane.setBackground(color);
}
)
哇..只是哇。我正在扩展JPanel,因为我预计将来会使用它的功能。 – JoJo 2012-07-27 01:36:09
干草,这是你的设计,如果你需要它,你需要:) – MadProgrammer 2012-07-27 01:42:59