try{ appearance++; String lookAndFeel=null; switch (appearance){ case 1://windows lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; lb_appearance.setText("<html>当前外观:<br>Windows</html>"); break; case 2: //Nimbus风格 lookAndFeel="com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"; lb_appearance.setText("<html>当前外观:<br>Nimbus</html>"); break; case 3: //Windows Classic风格 lookAndFeel="com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"; lb_appearance.setText("<html>当前外观:<br>Windows Classic</html>"); break; case 4://Motif风格 lookAndFeel="com.sun.java.swing.plaf.motif.MotifLookAndFeel"; lb_appearance.setText("<html>当前外观:<br>Motif</html>"); break; case 5: //默认风格 lookAndFeel="javax.swing.plaf.metal.MetalLookAndFeel"; lb_appearance.setText("<html>当前外观:<br>默认</html>"); break; } UIManager.setLookAndFeel(lookAndFeel); SwingUtilities.updateComponentTreeUI(mainFrame); if (appearance==5) appearance=0; }catch(Exception ex) { System.out.println(ex); }
时间: 2024-02-10 18:33:48 浏览: 66
这代码是用于在Java Swing界面中切换不同的外观(Look and Feel)。它通过增加一个名为“appearance”的整数变量来实现循环切换不同的外观样式。具体来说,它使用了不同的类来设置不同的外观,例如Windows、Nimbus、Windows Classic和Motif等。最后,它通过调用SwingUtilities.updateComponentTreeUI(mainFrame)来更新界面组件的UI。如果出现异常,则会将异常信息输出到控制台。
阅读全文