三、简单应用题
本题的功能是通过按钮来选择窗口显示的风格。窗口
中有三个按钮:“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();
}
2017年计算机二级《JAVA》模拟简单应用试题.doc正在阅读:
[2018年陕西中考数学试题及答案解析]2018年贵州贵阳中考数学试题及答案05-06
5月5端午节放假祝福短信11-03
澳洲留学生签证申请条件及调整内容!07-03
小学生日记:广播操比赛08-14
2018年中国铁路广东省广州局集团有限公司招聘公告【160人】05-25
幼儿园托班音乐课件08-25
2017年高考英语作文范文10篇|2017年高考英语作文范文(1)03-12
关于认清自我,改进不足的年终总结09-01
海贼王相关绕口令集锦02-17