试题查看

首页 > 计算机二级考试 > 试题查看
【分析解答题】

本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“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选项

你可能感兴趣的试题

在软件环境中()。A.软件方法是主导B.软件方法和软件工具并重C.软件工具是根本一旦中心节点出现故障则整个网络瘫痪的局域网的拓扑结构是()。A.星型结构B.树型提供showDocument()方法,使Applet能够请求浏览器访问特定URL阅读下面程序1publicclassTryextendsThread{2publ每个Java小应用程序必须定义为()。A.Applet类或JApplet类的子类若数组a定义为int[][]a=newint[3][4],则a是()。A.一维数