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("谢谢使用_(:зゝ∠)_"); } }

美国多IP站群VPS商家选择考虑因素和可选商家推荐

如今我们很多朋友做网站都比较多的采用站群模式,但是用站群模式我们很多人都知道要拆分到不同IP段。比如我们会选择不同的服务商,不同的机房,至少和我们每个服务器的IP地址差异化。于是,我们很多朋友会选择美国多IP站群VPS商家的产品。美国站群VPS主机商和我们普通的云服务器、VPS还是有区别的,比如站群服务器的IP分布情况,配置技术难度,以及我们成本是比普通的高,商家选择要靠谱的。我们在选择美国多IP...

月神科技 国内上新成都高防 全场八折促销续费同价!

月神科技是由江西月神科技有限公司运营的一家自营云产品的IDC服务商,提供香港安畅、香港沙田、美国CERA、成都电信等机房资源,月神科技有自己的用户群和拥有创宇认证,并且也有电商企业将业务架设在月神科技的平台上。本次带来的是全场八折促销,续费同价。并且上新了国内成都高防服务器,单机100G集群1.2T真实防御,上层屏蔽UDP,可定制CC策略。非常适合网站用户。官方网站:https://www.ysi...

易探云服务器怎么过户/转让?云服务器PUSH实操步骤

易探云服务器怎么过户/转让?易探云支持云服务器PUSH功能,该功能可将云服务器过户给指定用户。可带价PUSH,收到PUSH请求的用户在接收云服务器的同时,系统会扣除接收方的款项,同时扣除相关手续费,然后将款项打到发送方的账户下。易探云“PUSH服务器”的这一功能,可以让用户将闲置云服务器转让给更多需要购买的用户!易探云服务器怎么过户/PUSH?1.PUSH双方必须为认证用户:2.买家未接收前,卖家...

java课程设计报告为你推荐
在线编辑钉钉怎样设置在线编辑bft有懂BFT的行家吗?请简单的介绍下codereview代码review是什么意思 findbugs checkstyle pmdblastpBLAST有什么用?为什么要BLAST?战棋类最好玩的战棋类网页游戏是什么 要可以自己控制的cs躲猫猫cs躲猫猫怎么联机 今天在一个视频上看到的,T可以变成地图上的一个物品CT是找,请问怎么和老外联机电子听诊器听诊器有哪些用途的知识实数的定义数学中的“实数”是什么?赵锡成福茂航运公司的英文是什么?微店是什么微店和微商有什么区别呢
北京租服务器 vps推荐 免费cn域名 openv 国内免备案主机 wavecom web服务器架设软件 蜗牛魔方 工信部icp备案号 789电视网 双11秒杀 idc查询 中国电信宽带测速器 web服务器是什么 网购分享 smtp服务器地址 iki 服务器论坛 杭州电信宽带 双11促销 更多