⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jappletwithbuttons.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:

import java.awt.FlowLayout;
import java.awt.Container;
import java.awt.event.*;
import javax.swing.*;

public class JAppletWithButtons
    extends JApplet
    implements ActionListener
{
   JButton windLook = new JButton("Windows");
   JButton unixLook = new JButton("Unix");
   JButton javaLook = new JButton("Java");
   JLabel label = new JLabel("Welcome to Swing", SwingConstants.CENTER);
   public void init()
   {
      Container content = getContentPane();
      content.setLayout(new FlowLayout());
      content.add(label);
      content.add(windLook);
      windLook.addActionListener(this);
      content.add(unixLook);
      unixLook.addActionListener(this);
      content.add(javaLook);
      javaLook.addActionListener(this);
   }

   public void actionPerformed(ActionEvent ae)
   {
      String look = "javax.swing.plaf.metal.MetalLookAndFeel";
      if (ae.getSource() == javaLook)
      {
         look = "javax.swing.plaf.metal.MetalLookAndFeel";
      }
      else if (ae.getSource() == windLook)
      {
         look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
      }
      else if (ae.getSource() == unixLook)
      {
         look = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
      }
      try
      {
         UIManager.setLookAndFeel(look);
      }
      catch (Exception e)
      {
         System.err.println("Exception: " + e);
      }
      SwingUtilities.updateComponentTreeUI(this);
   }
}

⌨️ 快捷键说明

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