本题使用下拉菜单来控制字体。窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签h字符串的字体就随之改变。 importjavfl.awt.*; importjava.awt.event.*; importjavax.swing.*; cl

admin2013-12-02  23

问题 本题使用下拉菜单来控制字体。窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签h字符串的字体就随之改变。
importjavfl.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
classComboBoxFrameextendsJFrame{
publicComboBoxFrame(    );
setTitle(”java2”);
setSize(300,200);
addWindowListener(newWindowAdapter(    ){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
1);
style=newJComboBox(    );
style.setEditable(true);
style.addhem(“Serif”);
style.addhem(“SansSerif”);
style.addhem(“Monospaced”);
style.addhem(“Dialog”);
style.addhem(“Dialoglnput”);
style.addActionListener(this);
JPanelP=newJPanel(    );
P.add(style);
getC0ntentPane(    ).add(P,“South”);
panel=newComboBoxTestPanel(    );
getC0ntentPane(    ).add(panel,“Center”);
}
publicvoidactionPerformed(ActionEventevt){
JComboBoxsource=(JComboBox);
Stringitem=(String)source.getSeleetedhem(    );
panel.setStyle(item);
}
privateComboBoxTestPanelpanel;
privateJComboBoxstyle;
}
classComboBoxTestPanelextendsJPanel{
publicComboBoxTestPanel(    ){
setStyle(”Serif”);
}
publicvoidsetStyle(Strings){
setFont(newFont(s,Font.PLAIN,12));
repaint(    );
}
publicvoidpaintComponent(Graphicsg){
super.paintComponent(g);
g.drawstring(”WelcometoChina!”.0,50);
}
}
publicclassjava2{
publicstaticvoidmain(String[]args){
JFrameframe=newComboBoxFrame(    );
frame.show(    );
}

选项

答案第1处:implementsActionListener第2处:evl.getSource()

解析 第1处是实现ActionListener接口,程序中有窗口监听器的注册;第2处返回ActionEvent动作事件的最初发生对象。
转载请注明原文地址:https://kaotiyun.com/show/PQID777K
0

相关试题推荐
随机试题
最新回复(0)