java菜单和工具栏代码 java在菜单里添加工具栏

如何用JAVA实现工具栏上的下拉菜单java菜单和工具栏代码你做过java的GUI开发吗???
用netbeans或者给eclipse安装visual editor或swt designerjava菜单和工具栏代码,这样就可以进行可视化开发,你所说的那个就是众多swing控件中的一个,直接往frame里拖动就可以java菜单和工具栏代码了 。
java中菜单栏和工具栏,您请进!谢谢!当按下JMenuItem组件时java菜单和工具栏代码 , 就如同按下JButton按钮组件一般,都会产生ActionEvent事件 。因此我们可以在按钮事件java菜单和工具栏代码的方法中这样写,如下:
public void actionperformed(ActionEvent e){
if((e.getActionCommand()).equals("菜单java菜单和工具栏代码的名字")||(e.getActionCommand()).equals("工具栏中对应按钮的名字"))
{
//这里面就写这个菜单(工具按钮)要实现的功能
}
}
java的菜单代码怎么写?import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyMenu extends JFrame{
JMenuBar jmbar=new JMenuBar();
JMenu jmenu=new JMenu("颜色");
JMenuItem jmt1=new JMenuItem("红色"),
jmt2=new JMenuItem("黄色"),
jmt3=new JMenuItem("蓝色");
JPanel jp=new JPanel();
MyMenu(){
setTitle("菜单测试");
setSize(400,300);
setJMenuBar(jmbar);
jmbar.add(jmenu);
jmenu.add(jmt1);
jmenu.add(jmt2);
jmenu.add(jmt3);
add(jp);
jmt1.addActionListener(new MenuAction(this));
jmt2.addActionListener(new MenuAction(this));
jmt3.addActionListener(new MenuAction(this));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new MyMenu();
}
}
class MenuAction implements ActionListener{
MyMenu m;
MenuAction(MyMenu m){
this.m=m;
}
public void actionPerformed(ActionEvent e){
String color=e.getActionCommand();
if(color=="红色")m.jp.setBackground(Color.red);
else if(color=="黄色")m.jp.setBackground(Color.yellow);
else if(color=="蓝色")m.jp.setBackground(Color.blue);
}
}
不知道java菜单和工具栏代码你要什么事件代码,java菜单和工具栏代码我写java菜单和工具栏代码了个比较简单的你看适合不 。
java怎么设置工具栏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; //返回工具栏
}
//以下是我做项目的完整代码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);
【java菜单和工具栏代码 java在菜单里添加工具栏】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.heightscreenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.widthscreenSize.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.heightscreenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.widthscreenSize.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();
}
}
关于java菜单和工具栏代码和java在菜单里添加工具栏的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读