java问题请教:下面的程序我明明都在菜单中添加了菜单项,为啥只有最后一个菜单出来菜单项,前面的都没有

java问题请教:下面的程序我明明都在菜单中添加了菜单项,为啥只有最后一个菜单出来菜单项,前面的都没有,第1张

这是我写的一个图形界面,事件响应还没写,一个空壳子,你看看把

package indexFrame;

import javaawtFont;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaxswing;

import javatextDateFormat;

import javautil;

import javaxswing;

import javaxswingborderLineBorder;

import javaxswingborderTitledBorder;

import javaawtevent;

public class IndexFrameOfSystem extends JFrame implements ActionListener {

public void launchFrame()

{

setFrameImage();

setFrameJMenu();

setFrameWindow();

thissetTitle("Student's call System");

thissetSize(450,600);

thissetLocationRelativeTo(null);

thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

thissetVisible(true);

}

public void setFrameImage()

{

ImageIcon icon =new ImageIcon("src/image/Titlejpg");//换左上角图标

thissetIconImage(icongetImage());

}

public void setFrameJMenu()

{

mbadd(menuFile);

mbadd(menuWindow); //各自添加组件

mbadd(menuHelp);

menuFileadd(menuItemImport);

menuFileadd(menuItemExit);

menuWindowadd(menuItemshowclassInformation);

menuHelpadd(menuItemabout);

thissetJMenuBar(mb);

}

JMenuBar mb=new JMenuBar(); //菜单项的创建

JMenu menuFile=new JMenu("文件");

JMenuItem menuItemImport=new JMenuItem("导入名单");

JMenuItem menuItemExit=new JMenuItem("退出");

JMenu menuWindow =new JMenu("窗口");

JMenuItem menuItemshowclassInformation=new JMenuItem("显示班级信息");

JMenu menuHelp=new JMenu("帮助");

JMenuItem menuItemabout=new JMenuItem("关于");

public void setFrameWindow()

{

thissetLayout(null);

titlesetBounds(0,0,450,20);

thisadd(title);

classdianmingButtonsetBounds(40,40,100,50);

thisadd(classdianmingButton);

classtiwenButtonsetBounds(280,40,100,50);

thisadd(classtiwenButton);

txTextAreasetEditable(false);//不能在上面打字

txTextAreasetBounds(40,120,280,150);

thisadd(txTextArea);

xiyiweiButtonsetBounds(330,130,80,50);

thisadd(xiyiweiButton);

zhantingButtonsetBounds(330,210,80,50);

thisadd(zhantingButton);

quexiButtonsetBounds(40,280,80,30);

bGroupadd(quexiButton);

qingjiaButtonsetBounds(150,280,80,30);

bGroupadd(qingjiaButton);

zaotuiButtonsetBounds(260,280,80,30);

bGroupadd(zaotuiButton);

thisadd(quexiButton);

thisadd(qingjiaButton);

thisadd(zaotuiButton);

txtAreasetEditable(false);

txtFieldsetBounds(40,320,280,150);//注意添加坐标的是滚动面板,而不是JTextArea

thisadd( txtField);

baochunJButtonsetBounds(330,480,100,40);

thisadd(baochunJButton);

menuItemImportaddActionListener(this);//监听器

classdianmingButtonaddActionListener(this);

classtiwenButtonaddActionListener(this);

xiyiweiButtonaddActionListener(this);

zhantingButtonaddActionListener(this);

quexiButtonaddActionListener(this);

qingjiaButtonaddActionListener(this);

zaotuiButtonaddActionListener(this);

menuItemExitaddActionListener(this);

baochunJButtonaddActionListener(this);

menuItemshowclassInformationaddActionListener(this);

menuItemaboutaddActionListener(this);

}

JLabel title=new JLabel(" 江西农业大学点名系统");

private JButton classdianmingButton=new JButton("课堂点名");

private JButton classtiwenButton=new JButton("课堂提问");

private JTextField txTextArea=new JTextField();

private JButton xiyiweiButton=new JButton("下一位");

private JButton zhantingButton=new JButton("停止");

private JRadioButton quexiButton=new JRadioButton("缺席");

private JRadioButton qingjiaButton=new JRadioButton("请假");

private JRadioButton zaotuiButton=new JRadioButton("早退");

private ButtonGroup bGroup=new ButtonGroup();

private JTextArea txtArea=new JTextArea();

private JScrollPane txtField=new JScrollPane(txtArea);

private JButton baochunJButton=new JButton("保存名单");

public static void main(String[] args) {

// TODO Auto-generated method stub

IndexFrameOfSystem ui= new IndexFrameOfSystem();

uilaunchFrame();

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

}

}

方案一:用Eclipse自带的Export功能

步骤1:准备主清单文件 “MANIFESTMF”,

步骤2:右击Java工程选择Export—>选择JAR file—>Next

步骤3:选择要打包的文件,不需要的文件不必打包,减小打包后的jar文件大小,并进行选项配置如下

步骤4:选择我们在第一步中自定义的配置文件路径,这一步很重要,不能采用默认选项

方案二:安装Eclipse打包插件Fat Jar

Fat Jar Eclipse Plug-In是一个可以将Eclipse Java Project的所有资源打包进一个可执行jar文件的小工具,可以方便的完成各种打包任务,我们经常会来打jar包,但是eclipse自带的打包jar似乎不太够用,Fat Jar是eclipse的一个插件,特别是Fat Jar可以打成可执行Jar包,并且在等其他资源、引用外包方面使用起来更方便。

步骤1:右击工程项目选择Buile Fat Jar

步骤2:配置jar文件存放目录,主Main文件等,如下图

步骤3:选择所要用到的第三方jar包

其实Java提供return,是为了保持调用者与被调用者进行通信的关键。比如某个对象调用了一个方法,他需要根据这个方法不同的返回值进行不同的业务处理。如果没有return机制的话,那就只能进行单一的业务处理了,不存在多种情况了。返回值的意义就是保持方法的调用者与被调用者进行通信的关键,这和java中异常抛出的机制是一样的。下面跟你简单说说return的两种用法吧,希望对你有帮助,谢谢

return的常用作用有以下两种

一种是返回参数所用的关键字,假如一个有返回值的方法执行完了之后需要返回一个参数,示例:public string functionTest(){

String a = "abc";

return a;

}

那么这个方法被调用之后就会返回一个值为abc的字符串,string result = functionTest();

第二种用法是,代码执行到此处终止。

比如当代码执行到某个地方会出现几种结果,然后其中一种结果就不能执行后续代码,这时候在那里加上一个return就可以终止后面的代码执行。

可以把普通的Java程序做成真正的exe,也就是单一个exe就可以在没有安装JVM的机器上运行。这样的工具常见的有JET和gcj前者是收费的,而且做出来的exe还是需要一堆dll。推荐使用gcj他有windows和Linux版,直接下载zip包,不需要安装,里面有不少例子,一些build的批处理文件。从原理来说gcj自己实现了JVM规范,也就是你编写一个HelloWorldjava,其中的main方法为Systemoutprintln("foo");

当使用gcj把它做成exe(大约2M),运行这个exe时,会启动里面的一个小型jvm,在这上面跑HelloWorld。

其实,把Java做成纯exe实在是吃力不讨好,有很多限制,文件又大。

我比较倾向另几种做法:

使用InstallAnywhere等工具,制作一个exe的安装包

用户可以选择使用他机器上的JRE或是这个安装包内的JRE来运行程序

这是很常见的一种做法,如JBuilder就是这么做的。

这样的好处是不要求对方机器上装有JRE,而且你原来的程序不需要任何改动。

InstallAnywhere中一个压缩的JRE大概是8M。

制作成可执行的jar,也就是在META-INF的MANIFEST文件制定Main-Class

可以通过命令行java -jar jarfilejar来执行,windows默认的把jar使用javaw -jar打开,所以有些机器上可以直接双击jar运行。

制作伪exe,其实和上一种做法是一样的,只不过做成exe,调用系统的javaexe来运行它,这样的工具有nativeJ,exe4j等

其实Java不像VB,Delphi只是一个语言,而是一个平台。

jar是最常用的部署单元,做成exe没什么意思。

一、exe4j。

说明:exe4j可以将Jar文件制作成exe文件,但需jre支持,也可将Jar文件放在外面。

软件性质:共享软件

下载地址:>

以上就是关于java问题请教:下面的程序我明明都在菜单中添加了菜单项,为啥只有最后一个菜单出来菜单项,前面的都没有全部的内容,包括:java问题请教:下面的程序我明明都在菜单中添加了菜单项,为啥只有最后一个菜单出来菜单项,前面的都没有、如何把java程序打包成.jar、在Java中,return返回值的意义,为什么要用返回值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9469649.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存