我正在尝试更新我的外观和感觉而没有任何错误,但我无法弄清楚我做错了什么。
这是我的窗口类:
public class Window extends JFrame {
private static final long serialVersionUID = 1L;
public Window() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new MigLayout());
setExtendedState(JFrame.MAXIMIZED_BOTH);
setMinimumSize(new Dimension(600, 700));
setVisible(true);
setContentPane(new JPanel() {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
g.drawImage(new ImageIcon("start.jpg").getImage(), 0, 0, getWidth(),
getHeight(), this);
}
});
}
}
这是我更新 UI 的主要地方(外观和感觉)
public class Main {
public static void main(String[] args) {
Window.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
}
catch (UnsupportedLookAndFeelException e) {}
Window window = new Window();
}
}
控制台说我的错误来自这一行: Window window = new Window();
然后这一行: setContentPane(new JPanel() {
但是,如果我删除整个 setContentPane 块,则错误将指向构造函数。
任何帮助,将不胜感激。谢谢!