代码生成器Word文件下载.docx
- 文档编号:3033680
- 上传时间:2023-05-01
- 格式:DOCX
- 页数:16
- 大小:140.60KB
代码生成器Word文件下载.docx
《代码生成器Word文件下载.docx》由会员分享,可在线阅读,更多相关《代码生成器Word文件下载.docx(16页珍藏版)》请在冰点文库上搜索。
}
publicStringgetType()
returntype;
publicvoidsetField(Stringfield)
this.field=field;
publicStringgetField()
returnthis.field;
publicstaticStringtoFirsttoUpper(Stringstr)
Stringfirst=str.substring(0,1);
Stringlast=str.substring
(1);
returnfirst.toUpperCase()+last;
}
importjava.util.*;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.text.*;
publicclassMousePopMenuextendsJPopupMenu
{
privateJTextComponentjtc;
publicMousePopMenu(JTextComponentjtxc)
Toolkitkit=Toolkit.getDefaultToolkit();
this.jtc=jtxc;
JMenuItemcopy=newJMenuItem("
复制"
newImageIcon(kit.getImage("
018.gif"
)));
copy.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
jtc.copy();
}
});
JMenuItemcut=newJMenuItem("
剪切"
cut.addActionListener(newActionListener()
jtc.cut();
JMenuItemcopyall=newJMenuItem("
全部选中并复制"
copyall.addActionListener(newActionListener()
jtc.selectAll();
JMenuItempaste=newJMenuItem("
粘贴"
paste.addActionListener(newActionListener()
jtc.paste();
JMenuItemselectall=newJMenuItem("
全部选中"
selectall.addActionListener(newActionListener()
//setBorderPainted(false);
this.add(copy);
//this.addSeparator();
this.add(cut);
this.addSeparator();
this.add(selectall);
this.add(copyall);
this.add(paste);
publicclassCodeCreateextendsJFrame
privateArrayListfieldList;
privateJPopupMenupop;
publicCodeCreate()
this.setTitle("
代码生成器"
);
fieldList=newArrayList();
JPanelp=newJPanel();
p.setLayout(newBorderLayout());
finalJTextAreaarea=newJTextArea(30,50);
area.setTabSize(4);
area.addMouseListener(newMouseAdapter()
publicvoidmouseReleased(MouseEvente)
//System.out.println(e.isPopupTrigger());
if(e.isPopupTrigger())
{
pop=newMousePopMenu(area);
//pop.setLabel("
弹出菜单"
pop.show(area,e.getX(),e.getY());
//System.out.println(pop.getLabel());
}
JScrollPanejsp=newJScrollPane(area);
JLabellname=newJLabel("
类名"
finalJTextFieldname=newJTextField(10);
JLabelltype=newJLabel("
类型"
finalJTextFieldtype=newJTextField(10);
type.addMouseListener(newMouseAdapter()
publicvoidmouseEntered(MouseEvente)
type.setFocusable(true);
type.setFocusTraversalKeysEnabled(true);
type.selectAll();
JLabellfield=newJLabel("
类变量"
finalJTextFieldfield=newJTextField(10);
finalJTextAreafieldArea=newJTextArea();
fieldArea.setEditable(false);
fieldArea.setLineWrap(true);
fieldArea.setForeground(Color.pink);
JScrollPanefieldjsp=newJScrollPane(fieldArea);
JButtonadd=newJButton("
增加类变量"
JButtoncreate=newJButton("
生成代码"
JButtonclear=newJButton("
清除所有"
clear.addActionListener(newActionListener()
fieldList.clear();
fieldArea.setText("
"
area.setText("
add.addActionListener(newActionListener()
addField(field,type,fieldArea);
field.addKeyListener(newKeyAdapter()
publicvoidkeyReleased(KeyEvente)
if(e.getKeyCode()==KeyEvent.VK_ENTER)
addField(field,type,fieldArea);
create.addActionListener(newActionListener()
Stringclassname=name.getText().trim();
Stringclassf="
publicclass"
+classname+"
\n{\n"
;
Strings="
//所有的私有类变量
Stringmethod="
//所有的set和get方法
Stringconstr="
public"
()\n{\n}\n"
//空的构造器
StringconstrByarg="
//构造器里面的参数
StringmethodInConstr="
//构器里面调用的方法
for(inti=0;
i<
fieldList.size();
i++)
VarCodevar=(VarCode)fieldList.get(i);
StringvarType=var.getType();
StringvarField=var.getField();
//类变量
s=s+"
private"
+varType+"
"
+varField+"
\n"
constrByarg=constrByarg+varType+"
"
methodInConstr=methodInConstr+"
this.set"
+VarCode.toFirsttoUpper(varField)+"
("
//方法
method=method+"
publicvoidset"
)\n{\n"
+"
this."
="
\n}\n"
+"
public"
get"
()\n{\n"
returnthis."
constrByarg=constrByarg.substring(0,constrByarg.lastIndexOf("
));
constrByarg="
+constrByarg+"
+methodInConstr+"
}\n"
Stringclassl="
}\n"
area.setForeground(Color.blue);
area.setFont(newFont("
CourierNew"
Font.PLAIN,13));
area.setText(classf+s+constr+constrByarg+method+classl);
JPanelfieldPanel=newJPanel(newBorderLayout());
fieldPanel.add(fieldjsp,BorderLayout.CENTER);
fieldPanel.add(newJLabel("
已搞定的类变量"
),BorderLayout.NORTH);
JPanelbuttonPanel=newJPanel();
buttonPanel.add(lname);
buttonPanel.add(name);
buttonPanel.add(ltype);
buttonPanel.add(type);
buttonPanel.add(lfield);
buttonPanel.add(field);
buttonPanel.add(add);
buttonPanel.add(create);
buttonPanel.add(clear);
p.add(jsp,BorderLayout.CENTER);
p.add(fieldPanel,BorderLayout.EAST);
p.add(buttonPanel,BorderLayout.SOUTH);
this.setSize(800,650);
this.getContentPane().add(p);
publicstaticvoidmain(Stringar[])
CodeCreatec=newCodeCreate();
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setVisible(true);
privatevoidaddField(JTextFieldfield,JTextFieldtype,JTextAreafieldArea)
Stringstr_field=field.getText().trim();
Stringstr_type=type.getText().trim();
if(!
isEmp(str_field)&
&
!
isEmp(str_type))
VarCodevar=newVarCode();
var.setField(str_field);
var.setType(str_type);
fieldList.add(var);
fieldArea.append(str_type+"
+str_field+"
field.setText("
}
publicstaticbooleanisEmp(Stringstr)
if(str==null||str.trim().equals("
))
returntrue;
else
returnfalse;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 代码 生成器