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

📄 jframewithbuttons.java

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

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

public class JFrameWithButtons
    extends JFrame
    implements ActionListener
{
   private JButton windLook = new JButton("Windows");
   private JButton unixLook = new JButton("Unix");
   private JButton javaLook = new JButton("Java");
   private JLabel label = new JLabel("Welcome to Swing",
                                     SwingConstants.CENTER);
   private class WindowCloser
       extends WindowAdapter
   {
      public void windowClosing(WindowEvent we)
      {
         System.exit(0);
      }
   }

   public JFrameWithButtons()
   {
      super("JFrame with Buttons");
      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);
      addWindowListener(new WindowCloser());
      validate();
      pack();
      setVisible(true);
   }

   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);
         SwingUtilities.updateComponentTreeUI(this);
         pack();
      }
      catch (Exception e)
      {
         System.err.println("Exception: " + e);
      }
   }

   public static void main(String args[])
   {
      JFrameWithButtons jfb = new JFrameWithButtons();
   }
}

⌨️ 快捷键说明

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