「java一键生成代码源码」java代码自动生成

博主:adminadmin 2023-01-12 11:21:11 776

今天给各位分享java一键生成代码源码的知识,其中也会对java代码自动生成进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求一个用JAVA写的简单的记事本源代码程序

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.awt.datatransfer.*;

class MyMenuBar extends MenuBar{

public MyMenuBar(Frame parent){

parent.setMenuBar(this);

}

public void addMenus(String [] menus){

for(int i=0;imenus.length;i++)

add(new Menu(menus[i]));

}

public void addMenuItems(int menuNumber,String[] items){

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

if(items[i]!=null)

getMenu(menuNumber).add(new MenuItem(items[i]));

else getMenu(menuNumber).addSeparator();

}

}

public void addActionListener(ActionListener al){

for(int i=0;igetMenuCount();i++)

for(int j=0;jgetMenu(i).getItemCount();j++)

getMenu(i).getItem(j).addActionListener(al);

}

}

class MyFile{

private FileDialog fDlg;

public MyFile(Frame parent){

fDlg=new FileDialog(parent,"",FileDialog.LOAD);

}

private String getPath(){

return fDlg.getDirectory()+"\\"+fDlg.getFile();

}

public String getData() throws IOException{

fDlg.setTitle("打开");

fDlg.setMode(FileDialog.LOAD);

fDlg.setVisible(true);

BufferedReader br=new BufferedReader(new FileReader(getPath()));

StringBuffer sb=new StringBuffer();

String aline;

while((aline=br.readLine())!=null)

sb.append(aline+'\n');

br.close();

return sb.toString();

}

public void setData(String data) throws IOException{

fDlg.setTitle("保存");

fDlg.setMode(FileDialog.SAVE);

fDlg.setVisible(true);

BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));

bw.write(data);

bw.close();

}

}

class MyClipboard{

private Clipboard cb;

public MyClipboard(){

cb=Toolkit.getDefaultToolkit().getSystemClipboard();

}

public void setData(String data){

cb.setContents(new StringSelection(data),null);

}

public String getData(){

Transferable content=cb.getContents(null);

try{

return (String) content.getTransferData(DataFlavor.stringFlavor);

//DataFlavor.stringFlavor会将剪贴板中的字符串转换成Unicode码形式的String对象。

//DataFlavor类是与存储在剪贴板上的数据的形式有关的类。

}catch(Exception ue){}

return null;

}

}

class MyFindDialog extends Dialog implements ActionListener{

private Label lFind=new Label("查找字符串");

private Label lReplace=new Label("替换字符串");

private TextField tFind=new TextField(10);

private TextField tReplace=new TextField(10);

private Button bFind=new Button("查找");

private Button bReplace=new Button("替换");

private TextArea ta;

public MyFindDialog(Frame owner,TextArea ta){

super(owner,"查找",false);

this.ta=ta;

setLayout(null);

lFind.setBounds(10,30,80,20);

lReplace.setBounds(10,70,80,20);

tFind.setBounds(90,30,90,20);

tReplace.setBounds(90,70,90,20);

bFind.setBounds(190,30,80,20);

bReplace.setBounds(190,70,80,20);

add(lFind);

add(tFind);

add(bFind);

add(lReplace);

add(tReplace);

add(bReplace);

setResizable(false);

bFind.addActionListener(this);

bReplace.addActionListener(this);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

MyFindDialog.this.dispose();

}

});

}//构造函数结束

public void showFind(){

setTitle("查找");

setSize(280,60);

setVisible(true);

}

public void showReplace(){

setTitle("查找替换");

setSize(280,110);

setVisible(true);

}

private void find(){

String text=ta.getText();

String str=tFind.getText();

int end=text.length();

int len=str.length();

int start=ta.getSelectionEnd();

if(start==end) start=0;

for(;start=end-len;start++){

if(text.substring(start,start+len).equals(str)){

ta.setSelectionStart(start);

ta.setSelectionEnd(start+len);

return;

}

}

//若找不到待查字符串,则将光标置于末尾

ta.setSelectionStart(end);

ta.setSelectionEnd(end);

}

public Button getBFind() {

return bFind;

}

private void replace(){

String str=tReplace.getText();

if(ta.getSelectedText().equals(tFind.getText()))

ta.replaceRange(str,ta.getSelectionStart(),ta.getSelectionEnd());

else find();

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==bFind)

find();

else if(e.getSource()==bReplace)

replace();

}

}

public class MyMemo extends Frame implements ActionListener{

private TextArea editor=new TextArea(); //可编辑的TextArea

private MyFile mf=new MyFile(this);//MyFile对象

private MyClipboard cb=new MyClipboard();

private MyFindDialog findDlg=new MyFindDialog(this,editor);

public MyMemo(String title){ //构造函数

super(title);

MyMenuBar mb=new MyMenuBar(this);

//添加需要的菜单及菜单项

mb.addMenus(new String[]{"文件","编辑","查找","帮助"});

mb.addMenuItems(0,new String[]{"新建","打开","保存",null,"全选"});

mb.addMenuItems(1,new String[]{"剪贴","复制","粘贴","清除",null,"全选"});

mb.addMenuItems(2,new String[]{"查找",null,"查找替换"});

mb.addMenuItems(3,new String[]{"我的记事本信息"});

add(editor); //为菜单项注册动作时间监听器

mb.addActionListener(this);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

MyMemo.this.dispose();

}

}); //分号不能忘了

} //构造函数完

public void actionPerformed(ActionEvent e){

String selected=e.getActionCommand(); //获取菜单项标题

if(selected.equals("新建"))

editor.setText("");

else if(selected.equals("打开")){

try{

editor.setText(mf.getData());

}catch(IOException ie){}

}

else if(selected.equals("保存")){

try{

mf.setData(editor.getText());

}catch(IOException ie){}

}

else if(selected.equals("退出")){

dispose();

}

else if(selected.equals("剪贴")){

//将选中的字符串复制到剪贴板中并清除字符串

cb.setData(editor.getSelectedText());

editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());

}

else if(selected.equals("复制")){

cb.setData(editor.getSelectedText());

}

else if(selected.equals("粘贴")){

String str=cb.getData();

editor.replaceRange(str,editor.getSelectionStart(),editor.getSelectionEnd());

//粘贴在光标位置

}

else if(selected.equals("清除")){

editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());

}

else if(selected.equals("全选")){

editor.setSelectionStart(0);

editor.setSelectionEnd(editor.getText().length());

}

else if(selected.equals("查找")){

findDlg.showFind();

}

else if(selected.equals("查找替换")){

findDlg.showReplace();

}

}

public static void main(String[] args){

MyMemo memo=new MyMemo("记事本");

memo.setSize(650,450);

memo.setVisible(true);

}

}

java源代码怎么弄成exe文件,要详细步骤,我是菜鸟

这是几种比较常用的把java程序转换成exe文件的方法。

一、exe4j

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

软件性质:共享软件

二、JBuilder

说明:新版本的JBuilder可以直接把工程制作成各系统的可执行文件,包括Windows系统。

软件性质:商业软件

三、NativeJ

说明:与exe4j功能类似。

软件性质:共享软件

四、Excelsior JET

说明:可以直接将Java类文件制作成exe文件,除AWT和Swing及第三方图形接口外可不需jre支持(Java5.0不行)。

软件性质:共享软件

五、jshrink

说明:可将Jar文件打包进exe文件。同时具有混淆功能(这才是它的主要功能)。

软件性质:共享软件

六、InstallAnywhere

说明:打包工具,对Java打包最好用。可打包成各操作系统运行包。包括Windows系统。

软件性质:商业软件。

七、InstallShieldX

说明:与InstallAnywhere类似,但比InstallAnywhere功能强大。相对的,比较复杂,不易上手,我现在还没学会。

软件性质:商业软件。

怎么用MyEclipse软件实现JAVA源代码的打包,生成可执行文件。

MyEclipse 跟Eclipse 都不能生成 *.exe文件,但是能生成jar文件,只要你的电脑装了jdk就可以运行jar文件,这根装Framework原理差不错,如果你要生成exe文件要用其他软件,例如exe4j来制作,至于怎么搞你上网搜搜很多这方面的资料跟教程

怎样用Eclipse将Java源代码生成可执行文件

可以引出为”可执行jar“(项目必须有mian方法),然后双击运行即可。

第一步:在项目上右击,选择”Export“,之后找到”Runnable Jar file“。

第二步:在”Launch“下拉选中选择”main“方法入口类,然后选择”Browse“后,输入”jar“名称,点击”Finsh“即可完成可运行jar制作。

获取java生成exe的源代码

试试直接把扩展名强制弄成是.rar,然后解压,估计这样你就能够看到里面的包以及class等文件了。

= = 我没试过,楼主试试,可以的话顺便告诉我一声,谢谢

java代码生成器怎么用

zip包,然后自动下载下来

1.预先定义好模板

2.界面输入相关参数

3.解析模板生成代码并下载

最后放出源代码:

package com.et.controller.system.createcode;

import java.util.ArrayList;

import java.util.Date;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import com.et.controller.base.BaseController;

import com.et.util.DelAllFile;

import com.et.util.FileDownload;

import com.et.util.FileZip;

import com.et.util.Freemarker;

import com.et.util.PageData;

import com.et.util.PathUtil;

/**

* 类名称:FreemarkerController

* 创建人:Harries

* 创建时间:2015年1月12日

* @version

*/

@Controller

@RequestMapping(value=”/createCode”)

public class CreateCodeController extends BaseController {

/**

* 生成代码

*/

@RequestMapping(value=”/proCode”)

public void proCode(HttpServletResponse response) throws Exception{

PageData pd = new PageData();

pd = this.getPageData();

/* ============================================================================================= */

String packageName = pd.getString(“packageName”); //包名 ========1

String objectName = pd.getString(“objectName”); //类名 ========2

String tabletop = pd.getString(“tabletop”); //表前缀 ========3

tabletop = null == tabletop?””:tabletop.toUpperCase(); //表前缀转大写

String zindext = pd.getString(“zindex”); //属性总数

int zindex = 0;

if(null != zindext !””.equals(zindext)){

zindex = Integer.parseInt(zindext);

}

ListString[] fieldList = new ArrayListString[](); //属性集合 ========4

for(int i=0; i zindex; i++){

fieldList.add(pd.getString(“field”+i).split(“,fh,”)); //属性放到集合里面

}

MapString,Object root = new HashMapString,Object(); //创建数据模型

root.put(“fieldList”, fieldList);

root.put(“packageName”, packageName); //包名

root.put(“objectName”, objectName); //类名

root.put(“objectNameLower”, objectName.toLowerCase()); //类名(全小写)

root.put(“objectNameUpper”, objectName.toUpperCase()); //类名(全大写)

root.put(“tabletop”, tabletop); //表前缀

root.put(“nowDate”, new Date()); //当前日期

DelAllFile.delFolder(PathUtil.getClasspath()+”admin/ftl”); //生成代码前,先清空之前生成的代码

/* ============================================================================================= */

String filePath = “admin/ftl/code/”; //存放路径

String ftlPath = “createCode”; //ftl路径

/*生成controller*/

Freemarker.printFile(“controllerTemplate.ftl”, root, “controller/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Controller.java”, filePath, ftlPath);

/*生成service*/

Freemarker.printFile(“serviceTemplate.ftl”, root, “service/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Service.java”, filePath, ftlPath);

/*生成mybatis xml*/

Freemarker.printFile(“mapperMysqlTemplate.ftl”, root, “mybatis_mysql/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath);

Freemarker.printFile(“mapperOracleTemplate.ftl”, root, “mybatis_oracle/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath);

/*生成SQL脚本*/

Freemarker.printFile(“mysql_SQL_Template.ftl”, root, “mysql数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath);

Freemarker.printFile(“oracle_SQL_Template.ftl”, root, “oracle数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath);

/*生成jsp页面*/

Freemarker.printFile(“jsp_list_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_list.jsp”, filePath, ftlPath);

Freemarker.printFile(“jsp_edit_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_edit.jsp”, filePath, ftlPath);

/*生成说明文档*/

Freemarker.printFile(“docTemplate.ftl”, root, “说明.doc”, filePath, ftlPath);

//this.print(“oracle_SQL_Template.ftl”, root); 控制台打印

/*生成的全部代码压缩成zip文件*/

FileZip.zip(PathUtil.getClasspath()+”admin/ftl/code”, PathUtil.getClasspath()+”admin/ftl/code.zip”);

/*下载代码*/

FileDownload.fileDownload(response, PathUtil.getClasspath()+”admin/ftl/code.zip”, “code.zip”);

}

}

关于java一键生成代码源码和java代码自动生成的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。