Java JToolBar_1
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 stub JToolBar 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 { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } } private class saveButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } } private class exitButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JToolBar_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); } }
posted on 2012-05-31 05:04 java课程设计例子 阅读(195) 评论(0) 编辑 收藏 举报