java中工具栏使用代码 java菜单栏工具栏( 二 )


for(int i=0; i actions.length;i++){
JButton bt = new JButton(actions[i]);
bt.setRequestFocusEnabled(false);
//设置不需要焦点
toolBar.add(bt);//增加按钮到工具栏
}
return toolBar; //返回工具栏
}
//以下是java中工具栏使用代码我做项目的完整代码java中工具栏使用代码,java中工具栏使用代码你参考一下
/**************************************
* Title:数据库综合操作
* Description:text类
* date :2008-7-22
* author :yangcong
***************************************/
package framejava;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
//简单的文本编辑器
public class mainframe extends JFrame{
JPanel textPane = new JPanel(); //文本窗格java中工具栏使用代码,编辑窗口
JLabel statusBar = new JLabel("JAVA综合操作平台V1.1杨聪制作"); //状态栏
JFileChooser filechooser = new JFileChooser();//文本选择器
JButton shujuku =new JButton("数据库操作");
JButton wangluo = new JButton("网络操作");
JButton about = new JButton("关于");
JButton exit =new JButton("退出");
public mainframe(){ //构造函数
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setTitle("JAVA综合操作平台V1.1");//调用父类构造函数
Action[] actions={//Action数组,各种操作命令
new AboutAction(),
new ExitAction()
};
textPane.add(shujuku);
textPane.add(wangluo);
textPane.add(about);
textPane.add(exit);
/***********************************************************************/
shujuku.addActionListener(new mainframe_shujuku_actionAdapter(this));
shujuku.setSelected(true);
/***********************************************************************/
/***********************************************************************/
wangluo.addActionListener(new mainframe_wangluo_actionAdapter(this));
wangluo.setSelected(true);
/***********************************************************************/
about.addActionListener(actions[0]);
exit.addActionListener(actions[1]);
statusBar.setForeground(Color.red);
setJMenuBar(createJMenuBar(actions));
Container container= getContentPane();
container.add(createJToolBar(actions),BorderLayout.NORTH);
container.add(textPane,BorderLayout.CENTER);
container.add(statusBar,BorderLayout.SOUTH);
//mainframe m_view = new mainframe();
//m_view.pack();
//Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//Dimension frameSize = m_view.getSize();
//if (frameSize.heightscreenSize.height) {
//frameSize.height = screenSize.height;
//}
//if (frameSize.widthscreenSize.width) {
//frameSize.width = screenSize.width;
//}
//m_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
//
//m_view.setSize(260,200);
//m_view.setVisible(true);
setSize(260,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//关闭窗口时退出程序
}
private JMenuBar createJMenuBar(Action[] actions){//创建菜单栏
JMenuBar menubar = new JMenuBar(); //实例化菜单栏
JMenu menuFile = new JMenu("文件");
JMenu menuAbout = new JMenu("帮助");
menuAbout.add(new JMenuItem(actions[0]));
menuFile.add(new JMenuItem(actions[1]));
menubar.add(menuFile); //增加菜单
menubar.add(menuAbout);
return menubar;
}
private JToolBar createJToolBar(Action[] actions){//创建工具条

推荐阅读