简答题:本题的功能是通过按钮来选择窗口显示的风格。窗口 中有三个按钮:“Metal”、“Motif”和“Windows”,单击任

  • 题目分类:Java
  • 题目类型:简答题
  • 查看权限:VIP
题目内容:
本题的功能是通过按钮来选择窗口显示的风格。窗口
中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一
个按钮,就能将窗口的风格改变为按钮名称所对应的风格。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PlafPanel extends JPanel implements ActionLis-
tener
{public ()
{metaIButton=new JButton("Metal");
motifButtOn=new J Button("Motif");
windowsButton=new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
}
Dublic void actionPerformed(ActionEvent evt)
{Object source=evt.getSource();
String plaf="":
if(source= =metalButton)
plaf="javax.swing.plaf.metal.MetalLookAnd-
Feel";
else if(source= =motifButton)
plaf="com.sun.java.swing.plaf.motif.Moti-
fLookAndFeel";
else if(source= =windowsButton)
Dlaf="com.sun.java.swing.plaf.windows.Win-
dowsLookAndFeel";
try
{UIManager.setLookAndFeel( );
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception 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();
}
参考答案:
答案解析:

Zhang Ping jumps__________in his class.

Zhang Ping jumps__________in his class.A.high B.most high C.the highest

查看答案

阅读下面程序 public class Operators And Expressions(void equals

阅读下面程序 public class Operators And Expressions(void equals Methodl(){Strings

查看答案

Which of the following is NOT true?________

Which of the following is NOT true?________A.The temperature in a greenhouse i

查看答案

The phrase“pep talks”in Paragraph 3 means’talks’which_______

The phrase“pep talks”in Paragraph 3 means’talks’which________.A.encourage people

查看答案

Zhao从A到G选项中,选出合适的答案:

Zhao从A到G选项中,选出合适的答案:A.My child is the focus of my life. B.Family and work are b

查看答案