大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
我可以说一下思路:
站在用户的角度思考问题,与客户深入沟通,找到曲周网站设计与曲周网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站设计、企业官网、英文网站、手机端网站、网站推广、空间域名、网页空间、企业邮箱。业务覆盖曲周地区。
取到所有下拉框的值,还有这个输入框的值,比如第一个是: num1 第二个是运算符:* 第三个是:num2 第四个是结果: result
点击提交,给一个点击事件,把取到的值进行运算var cal= Integer.parseInt(num1)* Integer.parseInt(num2),cla是自己定义的,然后判断程序计算的结果是否和输入的结果相等,再给出相应的提示
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”);
}
}
应该有规定是多少范围内整数吧 还有就是加减乘除吧 随机就用math.random()乘范围出数 然后取整 加减乘数也用随机数switch判断1234分别是加减乘除 倒数用timer和timertask类实现 那个手机的得响应一个向下获取焦点事件 类似的onKeyReleaseDown吧 下一个组件.setFocus 提交就是onSubmit事件 处理action或直接跳到ftl或者jsp上处理 传入结果参数程序分别判断下正确个数 然后显示就行了 正确率乘5就是分数
java计算器源程序
java计算器
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class calculation extends JFrame
{public calculation() /*构造方法*/
{super("计数器");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initTextPanel(); /*文本框*/
initControlPanel(); /*控制键*/
initKeyPanel(); /*数字和运算符*/
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(TextPanel,BorderLayout.NORTH);
pane.add(ControlPanel,BorderLayout.CENTER);
pane.add(KeyPanel,BorderLayout.SOUTH);
pack();
try
{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception ex)
{;} /*设置Windons观感*/
SwingUtilities.updateComponentTreeUI(this);
setResizable(false);
setVisible(true);
}
private void initTextPanel() /*设置文本框*/
{ TextPanel=new JPanel();
TextPanel.setLayout(new FlowLayout());
Resultarea =new JTextField("0",25);
Resultarea.setEditable(false); /*设置不可编辑*/
Color color=Color.white;
Resultarea.setBackground(color); /*颜色*/
Resultarea.setHorizontalAlignment(JTextField.RIGHT); /*设置显示位置*/
TextPanel.add(Resultarea);
}
private void initControlPanel() /*设置控制键*/
{ControlPanel=new JPanel();
ControlPanel.setLayout(new GridLayout(1,3,4,4));
JButton b1=new JButton("Backspace"); /*Backspace键*/
b1.setFont(font1);
b1.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{String s1=Resultarea.getText();
int l=s1.length();
Resultarea.setText(s1.substring(0 ,l-1));
}
});
ControlPanel.add(b1);
JButton b2=new JButton("CE"); /*CE键*/
b2.setFont(font1);
b2.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{Resultarea.setText("0");
isNew=true;
}
});
ControlPanel.add(b2);
JButton b3=new JButton("C"); /*C键*/
b3.setFont(font1);
b3.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{Resultarea.setText("0");
pnum="";
operation="";
isNew=true;
}
});
ControlPanel.add(b3);
}
private void initKeyPanel() /*设置数字键和运算符键*/
{String key[] = {"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};
KeyPanel = new JPanel();
KeyPanel.setLayout(new GridLayout(4,5,4,4));
for(int i=0;i20;i++)
{String label = key[i];
JButton b = new JButton(label);
b.setActionCommand(key[i]);
b.setFont(font2);
KeyPanel.add(b);
b.addActionListener(new ActionListener() /*无名监听器*/
{public void actionPerformed(ActionEvent e)
{Key_actionPerformed(e);
}
});
}
}
public void Key_actionPerformed(ActionEvent e) /*数字键和运算符键无名监听器*/
{String s=(e.getActionCommand());
String st=Resultarea.getText();
if(s.equals("0")) /*输入数为0*/
{if(st.equals("0"))
return;
else
{if(!isNew)
Resultarea.setText(st+"0");
else
Resultarea.setText("0");
}
isNew=false;
return;
}
if(s.equals("+/-")) /*输入数为+/-*/
{double k=Double.parseDouble(st);
{if(k!=0)
display(-k);
}
return;
}
if(s.equals("1")||s.equals("2")||s.equals("3")||s.equals("4")||s.equals("5")||s.equals("6")||s.equals("7")||s.equals("8")||s.equals("9")) /*输入1-9*/
{if(!isNew)
Resultarea.setText(st+s);
else
{ Resultarea.setText(s);
isNew=false;
}
return;
}
if(s.equals(".")) /*输入小数点*/
{if(Resultarea.getText().indexOf(".")==-1) /*不存在小数点*/
{if(isNew)
{Resultarea.setText("0.");
isNew=false;
}
else
Resultarea.setText(st+".");
}
return;
}
isNew=true; /*按下运算符,输入新的数*/
if(s.equals("="))
{compute(s);
operation="";
}
else
{if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")) /*二目运算符号*/
{if(operation.equals(""))
{pnum=Resultarea.getText();
operation=s;
}
else
compute(s);
}
else /*一目运算*/
{Count count1=new Count(Double.parseDouble(st));
if(s.equals("sqrt"))
{
display(count1.sqrt());
}
else
{if(s.equals("1/x"))
{if(st.equals("0"))
{Resultarea.setText("除数不能为0.");
operation="";
pnum="";
}
else
display(count1.reciprocal()); /*求倒数*/
}
else
display(Double.parseDouble(st)/100); /*输入%,使当前显示的值除于100*/
}
}
}
}
private void compute(String s)
{if(s.equals("="))
{if(operation.equals(""))
return;
}
double data1=Double.parseDouble(pnum);
double data2=Double.parseDouble(Resultarea.getText());
Count count2=new Count(data1,data2); /*加减乘除计算*/
if(operation.equals("+"))
display((count2.plus()));
else
{if(operation.equals("-"))
display((count2.minus()));
else
{if(operation.equals("*"))
display((count2.multiply()));
else
if(operation.equals("/"))
{if(data2==0)
{Resultarea.setText("除数不能为0");
operation="";
pnum="";
return;
}
else
display((count2.divide()));
}
}
}
operation=""; /*符号为当前符*/
pnum=Resultarea.getText();/*运算数为当前文本数*/
}
public void display(double result) /*显示输出方法*/
{int a=(int)result;
if(a==result)
Resultarea.setText(String.valueOf(a));
else
Resultarea.setText(String.valueOf(result));
if(Resultarea.getText().equals("NaN"))
Resultarea.setText("输入函数无效");
}
private JPanel TextPanel; /*文本框棉板*/
private JTextField Resultarea; /*文本框*/
private JPanel ControlPanel; /*控制键键面板*/
private JPanel KeyPanel; /*数字键和运算符键面板*/
private Font font1=new Font("Dialog",0, 10); /*控制键字体*/
private Font font2 = new Font("Dialog",0,10); /*数字键和符号键字体*/
private String pnum=""; /*前操作数*/
private boolean isNew=true; /*控制是否是新数*/
private String operation=""; /*运算符*/
}
class tester /*测试类*/
{
public static void main(String[] args)
{
new calculation();
}
}