工具栏
来源:互联网 发布:知乎账号购买5w粉丝 编辑:程序博客网 时间:2024/04/29 13:02
package swing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class ToolBarTest {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
ToolBarFrame frame = new ToolBarFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class ToolBarFrame extends JFrame {
public ToolBarFrame() {
this.setTitle("ToolBar Test");
this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
panel = new JPanel();
this.add(panel, BorderLayout.CENTER);
Action blueAction = new ColorAction("Blue", new ImageIcon("c:/picture/1.gif"), Color.BLUE);
Action yellowAction = new ColorAction("Yellow", new ImageIcon("c:/picture/2.gif"), Color.YELLOW);
Action redAction = new ColorAction("Red", new ImageIcon("c:/picture/3.gif"), Color.RED);
Action exitAction = new AbstractAction("Exit", new ImageIcon("c:/picture/4.gif")) {
@Override
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
};
exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
//工具栏
JToolBar toolBar = new JToolBar();
toolBar.add(blueAction);
toolBar.add(yellowAction);
toolBar.add(redAction);
toolBar.addSeparator();
toolBar.add(exitAction);
this.add(toolBar, BorderLayout.NORTH);
//菜单栏
JMenu menu = new JMenu("Color");
menu.add(blueAction);
menu.add(yellowAction);
menu.add(redAction);
menu.addSeparator();
menu.add(exitAction);
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
this.setJMenuBar(menuBar);
}
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
private JPanel panel;
class ColorAction extends AbstractAction {
public ColorAction(String name, Icon icon, Color c) {
this.putValue(Action.NAME, name);
this.putValue(Action.SMALL_ICON, icon);
this.putValue(Action.SHORT_DESCRIPTION, name + " background");
this.putValue("Color", c);
}
@Override
public void actionPerformed(ActionEvent event) {
Color c = (Color) this.getValue("Color");
panel.setBackground(c);
}
}
}
- 工具栏
- 工具栏
- 工具栏
- 工具栏
- 工具栏
- 工具栏
- 工具栏
- 自定义工具栏
- 工具栏编程
- 创建工具栏
- 隐藏工具栏
- VC 工具栏
- 浮动工具栏
- 彩色工具栏
- 工具栏编程
- 工具栏设计
- 工具栏小结
- 工具栏介绍
- U盘 自动检测 windows服务,关闭服务造成SD卡不能自动识别
- objective-c入门(xcode helloworld程序 创建类)
- QPI extend
- delphi try except语句 和 try finally语句用法
- 如何解决系统不能正常关机
- 工具栏
- 增删改查小案例
- html中的特殊字符摘要
- 第六周实验指导--程序填空:按要求将缺少的代码填进去
- Loadrunner监控linux服务器资源
- 图片并行下载和顺序下载
- 基于JMF的视频传输源码(亲试可行)
- 【redhat5.5】 网络引导和无人值守安装配置
- 关于OpenGL模型视图矩阵的研究