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

📄 tabbedpanetest.java

📁 sun公司开发的,java2核心技术,卷II:高级性能,包括一系列的高级java应用技术,如数据库德连接,高级swing,多线程,软件本地化等等,本文件中则包含该书中的所用实例,配合该书使用,使对ja
💻 JAVA
字号:
/**
 * @version 1.00 1999-07-17
 * @author Cay Horstmann
 */

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class TabbedPaneTest
{  public static void main(String[] args)
   {  JFrame frame = new TabbedPaneFrame();
      frame.show();
   }
}

class TabbedPaneFrame extends JFrame
   implements ChangeListener
{  public TabbedPaneFrame()
   {  setTitle("TabbedPaneTest");
      setSize(400, 300);
      addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );

      tabbedPane = new JTabbedPane();
      tabbedPane.addChangeListener(this);

      /* we set the components to null and delay their
         loading until the tab is shown for the first time
      */

      ImageIcon icon = new ImageIcon("yellow-ball.gif");

      tabbedPane.addTab("Mercury", icon, null);
      tabbedPane.addTab("Venus", icon, null);
      tabbedPane.addTab("Earth", icon, null);
      tabbedPane.addTab("Mars", icon, null);
      tabbedPane.addTab("Jupiter", icon, null);
      tabbedPane.addTab("Saturn", icon, null);
      tabbedPane.addTab("Uranus", icon, null);
      tabbedPane.addTab("Neptune", icon, null);
      tabbedPane.addTab("Pluto", icon, null);

      getContentPane().add(tabbedPane, "Center");
   }

   public void stateChanged(ChangeEvent event)
   {  JTabbedPane pane = (JTabbedPane)event.getSource();

      // check if this tab still has a null component

      if (pane.getSelectedComponent() == null)
      {  // set the component to the image icon

         int n = pane.getSelectedIndex();
         String title = pane.getTitleAt(n);
         ImageIcon planetIcon = new ImageIcon(title + ".gif");
         pane.setComponentAt(n, new JLabel(planetIcon));

         // indicate that this tab has been visited--just for fun

         pane.setIconAt(n, new ImageIcon("red-ball.gif"));
      }
   }

   private JTabbedPane tabbedPane;
}

⌨️ 快捷键说明

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