行动按钮示例 : 按钮 « 图形用户界面 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 图形用户界面 » 按钮屏幕截图 
行动按钮示例
行动按钮示例
  
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRootPane;

public class ActionButtonSample {

  public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        String command = actionEvent.getActionCommand();
        System.out.println("Selected: " + command);
      }
    };

    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(22));

    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    button1.setActionCommand("First");
    button1.addActionListener(actionListener);
    content.add(button1);

    Icon warnIcon = new ImageIcon("Warn.gif");
    JButton button2 = new JButton(warnIcon);
    button2.setActionCommand("Second");
    button2.addActionListener(actionListener);
    content.add(button2);

    JButton button3 = new JButton("Warning", warnIcon);
    button3.setActionCommand("Third");
    button3.addActionListener(actionListener);
    content.add(button3);

    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
        "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    button4.setActionCommand("Fourth");
    button4.addActionListener(actionListener);
    content.add(button4);

    JRootPane rootPane = frame.getRootPane();
    rootPane.setDefaultButton(button2);

    frame.setSize(300200);
    frame.setVisible(true);
  }
}

           
         
    
  
Related examples in the same category
1. 从行动创建JButton组件
2. 各种图形界面按钮各种图形界面按钮
3. 响应按钮压力机响应按钮压力机
4. Putting buttons on an appletPutting buttons on an applet
5. Uses reflection to create groups of different types of AbstractButtonUses reflection to create groups of different types of AbstractButton
6. 回旋按钮的例子回旋按钮的例子
7. Create a JButton that does not show focusCreate a JButton that does not show focus
8. Demonstration of button events including Action, Item and Change event typesDemonstration of button events including Action, Item and Change event types
9. JToggleButton事件JToggleButton事件
10. An example of radio button menu items in actionAn example of radio button menu items in action
11. JToggleButton演示JToggleButton演示
12. 选按钮选按钮
13. Button demo: Mnemonic, alignment and action command Button demo: Mnemonic, alignment and action command
14. 按钮行动来改变面板的背景按钮行动来改变面板的背景
15. HTML按钮HTML按钮
16. 线左侧的理由。此标签的文本将中心的线路
17. Lines are left justified. This label text will center the lines
18. 标签第二行文字的italicizes
19. 改变JButton组件标签
20. Ploygon按钮Ploygon按钮
21. 简单的UI按钮简单的UI按钮
22. 显示按钮的图标标签显示按钮的图标标签
23. 显示一个按钮边界显示一个按钮边界
24. 显示按钮变图标显示按钮变图标
25. 显示按钮及各种标记对齐显示按钮及各种标记对齐
26. 工作与工具提示文本工作与工具提示文本
27. 共享按钮之间的模式
28. 共享JButton组件之间的行动共享JButton组件之间的行动
29. 显示讯息
30. 演示Html按钮演示Html按钮
31. 图形界面按钮演示图形界面按钮演示
32. LoadSave :按键行动LoadSave :按键行动
33. Button with ICON and Multiline Button with ICON and Multiline
34. 助记符样本助记符样本
35. 图形界面默认按钮图形界面默认按钮
36. 按钮图标,默认按钮, HTML格式的按钮,按钮助记符。按钮图标,默认按钮, HTML格式的按钮,按钮助记符。
37. Button icons, a default button, HTML in a button,and button mnemonics.
38. 添加图标翻转,并压到JButton组件
39. Adding a Disabled Icon to a JButton Component
40. Setting the Gap Size Between the Label and Icon in a JButton Component
41. 移动JButton组件图标
42. 添加一个图标到JButton组件
43. Moving the Label/Icon Pair in a JButton Component
44. If the action does not have an icon or a different icon must be used, add or change the icon using setIcon():
45. 动态更新的外观部分
46. 简单ToggleButton样本简单ToggleButton样本
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.