【分析解答题】
本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。 import jav
A、awt.*; import jav
A、awt.event.*; import javax.swing.*; class PlafPanel extends JPanel implementsActionLis-tener{public(){metaIButton=new JButton("Metal"); motifButtOn=new JButton("Motif"); windowsButton=new JButton("Windows"); add(metalButton); add(motifButton); add(windowsButton); metalButton.addActionListener(this); motifButton.addActionListener(this); windowsButton.addActionListener(this); }Dublic void actionPerformedActionEvent evt){Object source=evt.getSource(); String plaf="": if(source= =metalButton)plaf="javax.swing.plaf.metal.MetalLookAnd-Feel"; else if(source= =motifButton)plaf="com.sun.jav
A、swing.plaf.motif.Moti-fLookAndFeel"; else if(source= =windowsButton)Dlaf="com.sun.jav
A、swing.plaf.windows.Win-dowsLookAndFeel"; try{UIManager.setLookAndFeel( ); SwingUtilities.updateComponentTreeUI(this); }catchException e){)}private JButton metalButton; private JButton motifButton; private JButton windowsButton; }class PlafFrame extends JFrame{public PlafFrame(){ setTitle("simple"); setSize(300,200); addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(O); }}); Container contentPane=getContentPane(); contentPane.add(new PlafPanel()); }}public class java2{public static void main(String[]args)f JFrame frame=new PlafFrame(); frame.show(); }
查看答案解析
参考答案:
正在加载...
答案解析
正在加载...
根据网考网移动考试中心的统计,该试题:
0%的考友选择了A选项
0%的考友选择了B选项
0%的考友选择了C选项
0%的考友选择了D选项