java课程设计报告JAVA课设小学算数运算测试程序报告中界面设计部分的详细设计与关键问

java课程设计报告  时间:2021-08-12  阅读:()

急求java 计算器课程设计报告,有源码,

源码如下: import java.awt.*; import java.text.DecimalFormat; import java.awt.event.*; import javax.swing.*; public class Calculator extends JFrame { private Container container; private GridBagLayout layout; private GridBagConstraints constraints; private JTextField displayField;//计算结果显示区 DecimalFormat df; //设置数据输出精度 private String lastCommand;//保存+,-,*,/,=命令 private double result;//保存计算结果 private boolean start;//判断是否为数字的开始 public Calculator() { super("Calculator"); container=getContentPane(); layout=new GridBagLayout(); container.setLayout(layout); constraints=new GridBagConstraints(); start=true; result=0; df = new DecimalFormat("0.##############"); //设置数据输出精度(对于double型值) lastCommand = "="; displayField=new JTextField(20); displayField.setHorizontalAlignment(JTextField.RIGHT); constraints.gridx=0; constraints.gridy=0; constraints.gridwidth=4; constraints.gridheight=1; constraints.fill=GridBagConstraints.BOTH; constraints.weightx=100; constraints.weighty=100; layout.setConstraints(displayField,constraints); container.add(displayField); ActionListener insert = new InsertAction(); mand = new CommandAction(); addButton("Backspace",0,1,2,1,insert); addButton("CE",2,1,1,1,insert); addButton("C",3,1,1,1,insert); addButton("7",0,2,1,1,insert); addButton("8",1,2,1,1,insert); addButton("9",2,2,1,1,insert); addButton("/",3,2,1,mand); addButton("4",0,3,1,1,insert); addButton("5",1,3,1,1,insert); addButton("6",2,3,1,1,insert); addButton("*",3,3,1,mand); addButton("1",0,4,1,1,insert); addButton("2",1,4,1,1,insert); addButton("3",2,4,1,1,insert); addButton("-",3,4,1,mand); addButton("0",0,5,1,1,insert); addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值 addButton(".",2,5,1,1,insert); addButton("+",3,5,1,mand); addButton("=",0,6,4,mand); setSize(300,300); setVisible(true); } private void addButton(String label,int row,int column,int with,int height,ActionListener listener) { JButton button=new JButton(label); constraints.gridx=row; constraints.gridy=column; constraints.gridwidth=with; constraints.gridheight=height; constraints.fill=GridBagConstraints.BOTH; button.addActionListener(listener); layout.setConstraints(button,constraints); container.add(button); } private class InsertAction implements ActionListener { public void actionPerformed(ActionEvent event) { String input=event.getActionCommand(); if (start) { displayField.setText(""); start=false; if(input.equals("+/-")) displayField.setText(displayField.getText()+"-"); } if(!input.equals("+/-")) { if(input.equals("Backspace")) { String str=displayField.getText(); if(str.length()>0) displayField.setText(str.substring(0,str.length()-1)); } else if(input.equals("CE")||input.equals("C")) { displayField.setText("0"); start=true; } else displayField.setText(displayField.getText()+input); } } } private class CommandAction implements ActionListener { public void actionPerformed(ActionEvent evt) { mand=evt.getActionCommand(); if(start) { mand; } else { calculate(Double.parseDouble(displayField.getText())); mand; start=true; } } } public void calculate(double x) { if (lastCommand.equals("+")) result+= x; else if (lastCommand.equals("-")) result-=x; else if (lastCommand.equals("*")) result*=x; else if (lastCommand.equals("/")) result/=x; else if (lastCommand.equals("=")) result=x; displayField.setText(""+ df.format(result)); } public static void main(String []args) { Calculator calculator=new Calculator(); calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

求五子棋的Java课程设计

呵呵,代码自己测试: import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.awt.Color; public class enzit extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener { int color_Qizi=0;//旗子的颜色标识 0:白子 1:黑子 int intGame_Start=0;//游戏开始标志 0未开始 1游戏中 int intGame_Body[][]=new int[16][16]; //设置棋盘棋子状态 0 无子 1 白子 2 黑子 Button b1=new Button("游戏开始"); Button b2=new Button("重置游戏"); Label lblWin=new Label(" "); Checkbox ckbHB[]=new Checkbox[2]; CheckboxGroup ckgHB=new CheckboxGroup(); public void init() { setLayout(null); addMouseListener(this); add(b1); b1.setBounds(330,50,80,30); b1.addActionListener(this); add(b2); b2.setBounds(330,90,80,30); b2.addActionListener(this); ckbHB[0]=new Checkbox("白子先",ckgHB,false); ckbHB[0].setBounds(320,20,60,30); ckbHB[1]=new Checkbox("黑子先",ckgHB,false); ckbHB[1].setBounds(380,20,60,30); add(ckbHB[0]); add(ckbHB[1]); ckbHB[0].addItemListener(this); ckbHB[1].addItemListener(this); add(lblWin); lblWin.setBounds(330,130,80,30); Game_start_csh(); } public void itemStateChanged(ItemEvent e) { if (ckbHB[0].getState()) //选择黑子先还是白子先 { color_Qizi=0; } else { color_Qizi=1; } } public void actionPerformed(ActionEvent e) { Graphics g=getGraphics(); if (e.getSource()==b1) { Game_start(); } else { Game_re(); } } public void mousePressed(MouseEvent e){} public void mouseClicked(MouseEvent e) { Graphics g=getGraphics(); int x1,y1; x1=e.getX(); y1=e.getY(); if (e.getX()<20 || e.getX()>300 || e.getY()<20 || e.getY()>300) { return; } if (x1%20>10) { x1+=20; } if(y1%20>10) { y1+=20; } x1=x1/20*20; y1=y1/20*20; set_Qizi(x1,y1); } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseDragged(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void paint(Graphics g) { draw_qipan(g); } public void set_Qizi(int x,int y) //落子 { if (intGame_Start==0) //判断游戏未开始 { return; } if (intGame_Body[x/20][y/20]!=0) { return; } Graphics g=getGraphics(); if (color_Qizi==1)//判断黑子还是白子 { g.setColor(Color.black); color_Qizi=0; } else { g.setColor(Color.white); color_Qizi=1; } g.fillOval(x-10,y-10,20,20); intGame_Body[x/20][y/20]=color_Qizi+1; if (Game_win_1(x/20,y/20)) //判断输赢 { lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!"); intGame_Start=0; } if (Game_win_2(x/20,y/20)) //判断输赢 { lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!"); intGame_Start=0; } if (Game_win_3(x/20,y/20)) //判断输赢 { lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!"); intGame_Start=0; } if (Game_win_4(x/20,y/20)) //判断输赢 { lblWin.setText(Get_qizi_color(color_Qizi)+"赢了!"); intGame_Start=0; } } public String Get_qizi_color(int x) { if (x==0) { return "黑子"; } else { return "白子"; } } public void draw_qipan(Graphics G) //画棋盘 15*15 { G.setColor(Color.lightGray); G.fill3DRect(10,10,300,300,true); G.setColor(Color.black); for(int i=1;i<16;i++) { G.drawLine(20,20*i,300,20*i); G.drawLine(20*i,20,20*i,300); } } public void Game_start() //游戏开始 { intGame_Start=1; Game_btn_enable(false); b2.setEnabled(true); } public void Game_start_csh() //游戏开始初始化 { intGame_Start=0; Game_btn_enable(true); b2.setEnabled(false); ckbHB[0].setState(true); for (int i=0;i<16 ;i++ ) { for (int j=0;j<16 ;j++ ) { intGame_Body[i][j]=0; } } lblWin.setText(""); } public void Game_re() //游戏重新开始 { repaint(); Game_start_csh(); } public void Game_btn_enable(boolean e) //设置组件状态 { b1.setEnabled(e); b2.setEnabled(e); ckbHB[0].setEnabled(e); ckbHB[1].setEnabled(e); } public boolean Game_win_1(int x,int y) //判断输赢 横 { int x1,y1,t=1; x1=x; y1=y; for (int i=1;i<5 ;i++ ) { if (x1>15) { break; } if (intGame_Body[x1+i][y1]==intGame_Body[x][y]) { t+=1; } else { break; } } for (int i=1;i<5 ;i++ ) { if (x1<1) { break; } if(intGame_Body[x1-i][y1]==intGame_Body[x][y]) { t+=1; } else { break; } } if (t>4) { return true; } else { return false; } } public boolean Game_win_2(int x,int y) //判断输赢 竖 { int x1,y1,t=1; x1=x; y1=y; for (int i=1;i<5 ;i++ ) { if (x1>15) { break; } if (intGame_Body[x1][y1+i]==intGame_Body[x][y]) { t+=1; } else { break; } } for (int i=1;i<5 ;i++ ) { if (x1<1) { break; } if(intGame_Body[x1][y1-i]==intGame_Body[x][y]) { t+=1; } else { break; } } if (t>4) { return true; } else { return false; } } public boolean Game_win_3(int x,int y) //判断输赢 左斜 { int x1,y1,t=1; x1=x; y1=y; for (int i=1;i<5 ;i++ ) { if (x1>15) { break; } if (intGame_Body[x1+i][y1-i]==intGame_Body[x][y]) { t+=1; } else { break; } } for (int i=1;i<5 ;i++ ) { if (x1<1) { break; } if(intGame_Body[x1-i][y1+i]==intGame_Body[x][y]) { t+=1; } else { break; } } if (t>4) { return true; } else { return false; } } public boolean Game_win_4(int x,int y) //判断输赢 左斜 { int x1,y1,t=1; x1=x; y1=y; for (int i=1;i<5 ;i++ ) { if (x1>15) { break; } if (intGame_Body[x1+i][y1+i]==intGame_Body[x][y]) { t+=1; } else { break; } } for (int i=1;i<5 ;i++ ) { if (x1<1) { break; } if(intGame_Body[x1-i][y1-i]==intGame_Body[x][y]) { t+=1; } else { break; } } if (t>4) { return true; } else { return false; } } }

JAVA课设小学算数运算测试程序报告中界面设计部分的详细设计与关键问

package demo; import java.util.Scanner; public class Test { static Scanner sc = new Scanner(System.in); public static boolean isNum(String str) { boolean a = str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); boolean b = str.matches("^[-+]?$"); return a && !b; } public static double input(int i) { System.out.print("输入第" + i + "个数:"); String num = ""; do { num = sc.next(); if (!isNum(num)) { System.out.print("输入的不为数字,请重新输入:"); } } while (!isNum(num)); return Double.parseDouble(num); } public static String input2() { String operator = ""; boolean re; System.out.print("输入运算符(+、-、*、/、^):"); do { operator = sc.next(); re = operator.equals("+") || operator.equals("-") || operator.equals("*") || operator.equals("/") || operator.equals("^"); if (!re) { System.out.print("请输入(+、-、*、/、^)中的一个:"); } } while (!re); return operator; } public static void main(String[] args) { String judge = ""; do { double n1 = input(1); double n2 = input(2); String result = ""; double res = 0; String op = null; op = input2(); switch (op) { case "+": res = n1 + n2; break; case "-": res = n1 - n2; break; case "*": res = n1 * n2; break; case "/": if (n2 == 0) { result = "除数不能为0"; } else { res = n1 / n2; } break; case "^": res = Math.pow(n1, n2); break; } if (result.isEmpty()) { result = String.valueOf(res); } System.out.println("计算结果:" + n1 + op + n2 + "=" + result); System.out.print("是否继续?(Y/任意退出)"); judge = sc.next(); } while (judge.equals("Y") || judge.equals("y")); System.out.println("谢谢使用_(:зゝ∠)_"); } }

Sharktech:美国/荷兰独立服务器,10Gbps端口/不限流量/免费DDoS防护60G,319美元/月起

sharktech怎么样?sharktech (鲨鱼机房)是一家成立于 2003 年的知名美国老牌主机商,又称鲨鱼机房或者SK 机房,一直主打高防系列产品,提供独立服务器租用业务和 VPS 主机,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹,所有产品均提供 DDoS 防护。此文只整理他们家10Gbps专用服务器,此外该系列所有服务器都受到高达 60Gbps(可升级到 100Gbps)的保护。...

华纳云-618大促3折起,18元/月买CN2 GIA 2M 香港云,物理机高防同享,10M带宽独享三网直连,无限流量!

官方网站:点击访问华纳云活动官网活动方案:一、香港云服务器此次推出八种配置的香港云服务器,满足不同行业不同业务规模的客户需求,同时每种配置的云服务都有不同的带宽选择,灵活性更高,可用性更强,性价比更优质。配置带宽月付6折季付5.5折半年付5折年付4.5折2年付4折3年付3折购买1H1G2M/99180324576648直达购买5M/17331556710081134直达购买2H2G2M892444...

香港云服务器 1核 256M 19.9元/月 Mineserver Ltd

Mineserver(ASN142586|UK CompanyNumber 1351696),已经成立一年半。主营香港日本机房的VPS、物理服务器业务。Telegram群组: @mineserver1 | Discord群组: https://discord.gg/MTB8ww9GEA7折循环优惠:JP30(JPCN2宣布产品可以使用)8折循环优惠:CMI20(仅1024M以上套餐可以使用)9折循...

java课程设计报告为你推荐
手游代理手游代理前期得投资多少钱?有了解的吗?ripper名侦探柯南中JT Ripper 是啥意思?excel通配符怎样删除excel中的通配符getsockoptsocket的send()方法的发送目的地址放在哪个参数里面?word打字后面的字消失word中打字后面的一个字就不见了是什么原因啊?高手指教下,谢谢!!!!!中国银行卡号中国银行卡号6013826307000697803姓名是谁blastpblast 和bomb的区别rbooracle中rbo和cbo的区别html源代码求一个简单的HTML代码,在线等,急replacewithjquery中replaceall和replacewith的区别
广东虚拟主机 ipage 狗爹 免费cdn加速 win8.1企业版升级win10 css样式大全 web服务器架设软件 铁通流量查询 卡巴斯基永久免费版 最好的空间 太原联通测速平台 空间论坛 服务器维护方案 腾讯实名认证中心 服务器合租 流媒体加速 电信托管 无限流量 域名dns 浙江服务器 更多