hw17_3.java

来自「Java程序设计实例」· Java 代码 · 共 48 行

JAVA
48
字号
import java.awt.*;  
import java.awt.event.*;  
class hw17_3 extends Frame implements ItemListener
{
   static hw17_3 frm=new hw17_3(); 
   static List lst=new List();   
   static Label lab=new Label();   
   public static void main(String args[])
   {
      frm.setLayout(new BorderLayout());
      frm.setTitle("List class");       
      lst.add("Dialog");
      lst.add("Monospaced");
      lst.add("SansSerif");
      lst.add("Serif");  
      lab.setAlignment(Label.CENTER);     
      frm.setSize(200,150);      
      frm.add(lst,BorderLayout.NORTH);
      frm.add(lab,BorderLayout.CENTER);
      lst.addItemListener(frm);
      frm.setBackground(Color.yellow);
      frm.setVisible(true);       
   }
   public void itemStateChanged(ItemEvent e)
   {
      String str=lst.getSelectedItem(); 
      if(str=="Dialog")
      {
         lab.setText("Dialog");
         lab.setFont(new Font("Dialog",Font.PLAIN,20));
      }
      else if(str=="Monospaced")
      {
         lab.setText("Monospaced");
         lab.setFont(new Font("Monospaced",Font.PLAIN,20));
      }
      else if(str=="SansSerif")
      {
         lab.setText("SansSerif");
         lab.setFont(new Font("SansSerif",Font.PLAIN,20));
      }
      else if(str=="Serif")
      {
         lab.setText("Serif");
         lab.setFont(new Font("Serif",Font.PLAIN,20));
      }   
   }   
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?