buttonicon.java

来自「Swing组件」· Java 代码 · 共 54 行

JAVA
54
字号
//==============================================================
// ButtonIcon.java - Display icon images in JButton objects
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

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

public class ButtonIcon extends JFrame {

// Constructor does all the setup work
 public ButtonIcon() {

  // Select local system look and feel
  try {
   UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
  } catch (Exception e) { }

  // End program when window closes
  addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0);
   }
  });

  ImageIcon prevIcon = new ImageIcon("lefthand.gif");
  JButton prevButton = new JButton("Prev", prevIcon);
  prevButton.setToolTipText("Move to the previous page");
  ImageIcon nextIcon = new ImageIcon("righthand.gif");
  JButton nextButton = new JButton("Next", nextIcon);
  nextButton.setToolTipText("Move to the next page");

  Container content = getContentPane();
  content.setLayout(new FlowLayout());
  content.add(prevButton);
  content.add(nextButton);
 }

 public static void main(String[] args) {
  ButtonIcon app = new ButtonIcon();
  app.setTitle("Button Icon Demo");
  app.setSize(320, 120);
  app.show();
 }
}

⌨️ 快捷键说明

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