Topic: 请帮我看一看这段代码! (cannot resolve symbol 大家可以不理) |
Print this page |
1.请帮我看一看这段代码! (cannot resolve symbol 大家可以不理) | Copy to clipboard |
Posted by: q_yuan Posted on: 2004-11-09 19:51 请各位高手帮我看一看这段代码,并给出正确的!谢谢! import java.awt.*; import java.awt.event.*; import javax.swing.*; public class StyleChooser extends JPanel{ static JFrame frame; static String metal="Metal"; static String metalClassName="javax.swing.plaf.metal.MetalLookAnedFeel"; static String motif= "Motif"; static String motifClassName="sun.java.swing.plaf.motif.MotifLookAnedFeel"; static String windows= "Windows"; static String windowsClassName="sun.java.swing.plaf.windows.WindowsLookAnedFeel"; JRadioButton metalButton,motifButton,windowsButton; public StyleChooser(){ JLabel label= new JLabel("Try the style Swing has"); metalButton = new JRadioButton(metal); metalButton.setMnemonic('o'); metalButton.setActionCommand(metalClassName); motifButton = new JRadioButton(motif); motifButton.setMnemonic('m'); motifButton.setActionCommand(motifClassName); windowsButton = new JRadioButton(windows); windowsButton.setMnemonic('w'); windowsButton.setActionCommand(windowsClassName); ButtonGroup group = new ButtonGroup(); group.add(metalButton); group.add(motifButton); group.add(windowsButton); RadioListener myListener = new RadioListener(); metalButton.addActionListener(myListener); motifButton.addActionListener(myListener); windowsButton.addActionListener(myListener); add(label); add(metalButton); add(motifButton); add(windowsButton); } class RadioListener implements ActionListener{ public void actionPerformed(ActionEvent e){ String lnfName = e.getActionCommand(); try{ IManager.setLookAndFeel(lnfName); wingUtilities.updateComponentTreeUI(frame); frame.pack(); }catch(Exception e){ JRadioButton button =(JRadioButton)e.getSource(); button.setEnabled(false); updateState(); System.err.println("Could not load LookAndFeel:" + lnfName); } } } public void updateState(){ String lnfName = UIManager.getLookAndFeel().getClass().getName(); if(lnfName.indexOf(metal)>=0){metalButton.setSelected(true);} else if (lnfName.indexOf(motif)>=0){motifButton.setSelected(true);} else if (lnfName.indexOf(windows)>=0){windowsButton.setSelected(true);} else{System.err.println("StyleChooser is Using an Unkown L&F:" + lnfName);} } public static void main(String[] arg){ StyleChooser panel = new StyleChooser(); frame=new JFrame("StyleChooser"); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); frame.getContentPane().add("Center",panel); frame.pack(); frame.setVisible(true); panel.updateState(); } } 我编译的时候出现了错误提示为: D:\Program Files\Xinox Software\JCreator Pro\MyProjects\FramPanel\StyleChooser.java:41: cannot resolve symbol symbol : variable IManager location: class StyleChooser.RadioListener IManager.setLookAndFeel(lnfName); ^ D:\Program Files\Xinox Software\JCreator Pro\MyProjects\FramPanel\StyleChooser.java:42: cannot resolve symbol symbol : variable WingUtilities location: class StyleChooser.RadioListener WingUtilities.updateComponentTreeUI(frame); ^ D:\Program Files\Xinox Software\JCreator Pro\MyProjects\FramPanel\StyleChooser.java:44: e is already defined in actionPerformed(java.awt.event.ActionEvent) }catch(Exception e){ ^ D:\Program Files\Xinox Software\JCreator Pro\MyProjects\FramPanel\StyleChooser.java:45: cannot resolve symbol symbol : method getSource () location: class java.lang.Exception JRadioButton button =(JRadioButton)e.getSource(); ^ |
2.Re:请帮我看一看这段代码! (cannot resolve symbol) [Re: q_yuan] | Copy to clipboard |
Posted by: why Posted on: 2004-11-09 23:32 try{ UIManager.setLookAndFeel(lnfName); SwingUtilities.updateComponentTreeUI(frame); frame.pack(); }catch(Exception ex){ 又是毫无意义的标题! 没有格式化、难看死的源码! 而且都是cannot resolve symbol的问题,应该自己解决! (再懒也可以用Google搜 IManager.setLookAndFeel 和 wingUtilities.updateComponentTreeUI 吧) 自己不肯用心一点,只顾求人,就不要学GUI方面的东西吧! 下次这种问题,见即删! |
3.Re:请帮我看一看这段代码! (cannot resolve symbol 大家可以不理) [Re: q_yuan] | Copy to clipboard |
Posted by: why Posted on: 2004-11-10 08:43 抄 chengbd 版主的话﹕ 不应该先把自己首先放在一个”新手“的位置上,而不亲自想办法解决问题,请您在群里看看,真的高手都是自己解决问题的,要问也是请教”方向“性的问题!如果遇到问题时总是问别人,我想这样永远也是新手。 http://www.cjsdn.net/post/view?bid=51&id=122324 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |