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

#消息# contabo:德国老牌机房新增美国“纽约、西雅图”数据中心,免设置费

运作了18年的德国老牌机房contabo在继去年4月开办了第一个美国数据中心(中部城市:圣路易斯)后立马在本月全新上马两个数据中心:纽约、西雅图。当前,为庆祝美国独立日,美国三个数据中心的VPS全部免除设置费,VPS本身的配置很高,价格适中,有较高的性价比!官方网站:https://contabo.com/en/SSD VPSKVM虚拟,纯SSD阵列,不限制流量,自带一个IPv4内存CPUSSD带...

月神科技-美国CERA 5折半价倒计时,上新华中100G高防云59起!

官方网站:点击访问月神科技官网优惠码:美国优惠方案:CPU:E5-2696V2,机房:国人热衷的优质 CeraNetworks机房,优惠码:3wuZD43F 【过期时间:5.31,季付年付均可用】活动方案:1、美国机房:洛杉矶CN2-GIA,100%高性能核心:2核CPU内存:2GB硬盘:50GB流量:Unmilited端口:10Mbps架构:KVM折后价:15元/月、150元/年传送:购买链接洛...

DMIT(季度$28.88)调整洛杉矶CN2 GIA优化端口

对于DMIT商家已经关注有一些时候,看到不少的隔壁朋友们都有分享到,但是这篇还是我第一次分享这个服务商。根据看介绍,DMIT是一家成立于2017年的美国商家,据说是由几位留美学生创立的,数据中心位于香港、伯力G-Core和洛杉矶,主打香港CN2直连云服务器、美国CN2直连云服务器产品。最近看到DMIT商家有对洛杉矶CN2 GIA VPS端口进行了升级,不过价格没有变化,依然是季付28.88美元起。...

java课程设计报告为你推荐
extractdataxp3文件怎么打开怎样进入观看?lazyloadlazyload实现的是什么功能免费erp最方便使用的免费erp软件有哪些中国银行卡号中行卡号有多少位?有12位的么?boltzmann格子boltzmann方法应用及常见的程序代码在哪有详细介绍diskgenius免费版diskgenius免费版怎么用系统登录界面谁知道XP系统的登录界面。和启动界面怎么更改的 急团购网源码最近看到团购挺火的,我也想做一个,请大家推荐个稳定的团购网站源码?免杀远控远控+免杀,到底是怎么一回事?廖华100个成语典故及其历史人物故事 南京廖华
海外主机 域名主机空间 亚洲大于500m fastdomain jsp主机 魔兽世界台湾服务器 牛人与腾讯客服对话 三拼域名 jsp空间 服务器维护方案 服务器合租 免费网页申请 申请网站 阿里云官方网站 英国伦敦 域名转入 购买空间 杭州电信宽带 privatetracker 时间服务器 更多