java调试视图工具栏_java怎么设置工具栏

展开全部

private JMenuBar createJMenuBar(Action[] actions){//创建菜单32313133353236313431303231363533e59b9ee7ad9431333236383561栏

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){//创建工具条

JToolBar toolBar = new JToolBar();//实例化工具条

for(int i=0; i< actions.length;i++){

JButton bt = new JButton(actions[i]);

bt.setRequestFocusEnabled(false);

//设置不需要焦点

toolBar.add(bt);//增加按钮到工具栏

}

return toolBar; //返回工具栏

}

//以下是我做项目的完整代码,你参考一下

/**************************************

* 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(); //文本窗格,编辑窗口

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.height > screenSize.height) {

// frameSize.height = screenSize.height;

// }

// if (frameSize.width > screenSize.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){//创建工具条

JToolBar toolBar = new JToolBar();//实例化工具条

for(int i=0; i< actions.length;i++){

JButton bt = new JButton(actions[i]);

bt.setRequestFocusEnabled(false);

//设置不需要焦点

toolBar.add(bt);//增加按钮到工具栏

}

return toolBar; //返回工具栏

}

/**************************数据库动作操作*************************************/

void shujuku_actionPerformed(ActionEvent e) {

shujuku.setSelected(false);

datamainframe d_view = new datamainframe();

d_view.pack();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = d_view.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

d_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

d_view.setSize(270,190);

d_view.setVisible(true);

}

class mainframe_shujuku_actionAdapter

implements java.awt.event.ActionListener {

mainframe adaptee;

mainframe_shujuku_actionAdapter(mainframe adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.shujuku_actionPerformed(e);

}

}

/***********************************************************************/

/********************网络动作操作**************************************/

void wangluo_actionPerformed(ActionEvent e) {

wangluo.setSelected(false);

netview n_view = new netview();

n_view.pack();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = n_view.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

n_view.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

n_view.setSize(800,700);

n_view.setVisible(true);

}

class mainframe_wangluo_actionAdapter

implements java.awt.event.ActionListener {

mainframe adaptee;

mainframe_wangluo_actionAdapter(mainframe adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.wangluo_actionPerformed(e);

}

}

/***********************************************************************/

class ExitAction extends AbstractAction{ //退出命令

public ExitAction(){

super("退出");

}

public void actionPerformed(ActionEvent e){

System.exit(0);

}

}

class AboutAction extends AbstractAction{//关于选项命令

public AboutAction(){

super("关于");

}

public void actionPerformed(ActionEvent e){

JOptionPane.showMessageDialog(mainframe.this,"JAVA综合操作平台V1.1\n"+"杨聪制作");

}

}

public static void main(String args[]){

new mainframe();

}

}

参考资料:

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值