我剛剛發現這真的很棒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