简答题:本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之改变

  • 题目分类:Java
  • 题目类型:简答题
  • 查看权限:VIP
题目内容:
本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之改变。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ComboBoxFrame extends JFrame {
public ComboBoxFrame(){
setTitle("java2");
setSize(300,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
style=new JComboBox():
style.setEditable(true);
style.addhem("Serif");
style.addItem("SansSerif");
style.addhem("Monospaced");
style.addhem("Dialog");
style.addhem("Dialoglnput");
style.addActionListener(this);
JPanel p=new JPanel();
P.add(style);
getContentPane().add(p,"South");
panel=new ComboBoxTestPanel();
getContentPane().add(panel,"Center");
}
public void actionPerformed(ActionEvent evt){
JComboBox source=(JComboBox)
String item=(String)source.getSelectedhem():
panel.setStyle(item);
}
private ComboBoxTestPanel panel;
private JComboBox style;
}
class ComboBoxTestPanel extends JPanel{
public ComboBoxTestPanel(){
setStyle("Serif");
}
public void setStyle(String s){
setFont(new Font(S,Font.PLAIN,12));
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
9.drawString("Welcome to China!",0,50);
}
}
public class java2{
public static void main(String[]args){
JFrame frame=new ComboBoxFrame();
frame.show();
}
}
参考答案:
答案解析:

在窗体中有一个命令按钮Commandl和一个文本框Textl,编写事件代码如下:Private Sub Commandl

在窗体中有一个命令按钮Commandl和一个文本框Textl,编写事件代码如下:Private Sub Commandl—Click(  ) For i=1

查看答案

启动窗体时,系统首先执行的事件过程是(  )。

启动窗体时,系统首先执行的事件过程是(  )。 A.Load B.Click C.Unload D.GotFocus

查看答案

在学生表中要查找所有年龄小于20岁且姓王的男生,应采用的关系运算是(  )。

在学生表中要查找所有年龄小于20岁且姓王的男生,应采用的关系运算是(  )。 A.选择 B.投影 C.连接 D.比较

查看答案

下列事件监听器中,无法对TextField对象进行事件监听和处理的是(  )。

下列事件监听器中,无法对TextField对象进行事件监听和处理的是(  )。 A.ActionListener B.FocusListener C.Mouse

查看答案

本题提取字符串“China is a great country.”中的前5个字符生成一个新的字符串,并将剩余字符组成另

本题提取字符串“China is a great country.”中的前5个字符生成一个新的字符串,并将剩余字符组成另外一个新的字符串,最后将两个新的字符串连

查看答案