Java JToolBar_1

来源:互联网 发布:同花顺模拟炒股软件 编辑:程序博客网 时间:2024/05/17 01:05

package com.han;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JToolBar;public class JToolBar_1 extends JFrame {/** *  */private static final long serialVersionUID = -5613166990529085530L;static Dimension dimension;public JToolBar_1() {// TODO Auto-generated constructor stubJToolBar toolBar = new JToolBar("工具栏");toolBar.setFloatable(false);// toolBar.setFloatable(true);getContentPane().add(toolBar, BorderLayout.NORTH);JButton newButton = new JButton("新建");toolBar.add(newButton);newButton.addActionListener(new newButtonListener());toolBar.addSeparator();JButton saveButton = new JButton("保存");toolBar.add(saveButton);saveButton.addActionListener(new saveButtonListener());toolBar.addSeparator(new Dimension(20, 0));JButton exitButton = new JButton("退出");toolBar.add(exitButton);exitButton.addActionListener(new exitButtonListener());dimension = toolBar.getPreferredSize();}private class newButtonListener implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}private class saveButtonListener implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}private class exitButtonListener implements ActionListener {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubJToolBar_1 frame = new JToolBar_1();frame.setTitle("使用工具栏");frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Rectangle rectangle = new Rectangle(100, 100, dimension.width + 300,dimension.width + 100);frame.setBounds(rectangle);}}


原创粉丝点击