万能百科  > 计算机   > 

[填空题] 本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif和“WindoWS“,单击任何一个按钮,就能将窗口的风格改变

2021-07-20   

[填空题] 本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif和“WindoWS“,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。

import java.awt*;

import java.awt.event.*;

import javax.swing.*;

class PlafPanel extends JPanel implements Actionlis-tener

public______()

metalButton=new JButton("Metal");

motifButton=new JButton("Motif");

windowsButton=new JButton("Windows");

add(metalButton);

add(motifButton);

add(windowsButton);

metalButlon.addActionListener(this);

motifButton.addActionListener(this);

windowsButton.addActionListener(this);

public void actionPerformed(ActionEvent evt)

Object source=evt.getSource();

string plaf="";

if(source==metaIButton)

pIaF="javax.swing.plaf.metal.MetalLookAncl-Feel";

else if(source==motifButton)

p

正确答案:

第1处:PlafPanel 笫2处:plaf

参考解析:

第一处由题意可知,类PlafPanel缺少构造函数,所以填PlafPanel。第二处是通过String类型的对象plaf,和UIManager.selLookAndFeel()方法实现显示风格的切换.

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签