看起来您正在阅读《Sams 在 24 小时内自学 Java,第 6 版?
无论如何,你可以这样做:
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class SalutonFrame extends JFrame {
public SalutonFrame() throws UnsupportedLookAndFeelException {
super("Saluton Mondo!");
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
JFrame someFrame = new JFrame();
setSize(350, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch (Exception exc) {
// error handling
}
}
}
或者你可以这样做:
import javax.swing.*;
public class SalutonFrame extends JFrame {
public SalutonFrame() {
super("Saluton Frame");
setLookAndFeel();
setSize(350, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private void setLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception exc) {
// error handling
}
}
public static void main(String[] args) {
SalutonFrame sal = new SalutonFrame();
}
}