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

RackNerd:便宜vps补货/1核/768M内存/12G SSD/2T流量/1G带宽,可选机房圣何塞/芝加哥/达拉斯/亚特拉大/荷兰/$9.49/年

RackNerd今天补货了3款便宜vps,最便宜的仅$9.49/年, 硬盘是SSD RAID-10 Storage,共享G口带宽,最低配给的流量也有2T,注意,这3款补货的便宜vps是intel平台。官方网站便宜VPS套餐机型均为KVM虚拟,SolusVM Control Panel ,硬盘是SSD RAID-10 Storage,共享G口带宽,大流量。CPU:1核心内存:768 MB硬盘:12 ...

NameSilo域名优惠码活动

NameSilo是通过之前的感恩节优惠活动中认识到这家注册商的,于是今天早上花了点时间专门了解了NameSilo优惠码和商家的详细信息。该商家只销售域名,他们家的域名销售价格还是中规中矩的,没有像godaddy域名标价和使用优惠之后的价格悬殊很大,而且其特色就是该域名平台提供免费的域名停放、免费隐私保护等功能。namesilo新注册域名价格列表,NameSilo官方网站:www.namesilo....

Gcore(75折)迈阿密E5-2623v4 CPU独立服务器

部落分享过多次G-core(gcorelabs)的产品及评测信息,以VPS主机为主,距离上一次分享商家的独立服务器还在2年多前,本月初商家针对迈阿密机房限定E5-2623v4 CPU的独立服务器推出75折优惠码,活动将在9月30日到期,这里再分享下。G-core(gcorelabs)是一家总部位于卢森堡的国外主机商,主要提供基于KVM架构的VPS主机和独立服务器租用等,数据中心包括俄罗斯、美国、日...

java课程设计报告为你推荐
可以访问违规网站的浏览器电脑上浏览器的重要权限有哪些,比如有可以访问系统文件之类的权限吗?百度云论坛哪里需要资源网盘分流?论坛、网站介绍一个……provisionedNIST的云计算定义巴西时区巴西与中国的时差是多少局域网ip扫描工具如何扫描局域网使用的设备赵锡成美国杰出华人手机壳生产厂家手机保护套保护壳厂家传奇私服教程怎样开传奇SF?我要具体详细的步骤微信收费微信提现收费是怎么计算的 从什么时候开始收费spinmaster那个街球队 叫什么And1的 球队和球员介绍
中文域名申请 免费申请域名和空间 贝锐花生壳域名 securitycenter awardspace inmotionhosting 免费主机 国外服务器网站 NetSpeeder 云图标 免费个人网站申请 免费网站申请 165邮箱 合租空间 免费dns解析 购买国外空间 常州联通宽带 中国电信测速网站 德讯 asp空间 更多