下午闲的没事,就用以前写的一个表达式计算器类,写了一个带界面的简单的计算器。界面如下:
由于第一次使用Swing,不是很了解,界面元素没有布局,而是直接通过像素来定位的,-_-||
例如加减乘除按钮:
if (oJbadd == null) { oJbadd = new javax.swing.JButton(); oJbadd.setBounds(PADDING_LEFT+2+BUTTON_WIDTH, 280, BUTTON_WIDTH, BUTTON_HEIGTH); oJbadd.setText("+"); } if (oJbsub == null) { oJbsub = new javax.swing.JButton(); oJbsub.setBounds(PADDING_LEFT+4+2*BUTTON_WIDTH, 280, BUTTON_WIDTH, BUTTON_HEIGTH); oJbsub.setText("-"); } if (oJbmut == null) { oJbmut = new javax.swing.JButton(); oJbmut.setBounds(PADDING_LEFT+6+3*BUTTON_WIDTH, 280, BUTTON_WIDTH, BUTTON_HEIGTH); oJbmut.setText("*"); } if (oJbdiv == null) { oJbdiv = new javax.swing.JButton(); oJbdiv.setBounds(PADDING_LEFT+8+4*BUTTON_WIDTH, 280, BUTTON_WIDTH, BUTTON_HEIGTH); oJbdiv.setText("/"); }
源码参考:http://download.csdn.net/detail/he_qiao_2010/6718075
关于更多表达式计算器的东西大家可以看看这里:
Android表达式计算器: http://blog.csdn.net/he_qiao/article/details/10213121
利用SLR实现可编程计算器(表达式求值): http://blog.csdn.net/he_qiao/article/details/8203713
OC实现的表达式计算器:http://blog.csdn.net/he_qiao/article/details/10217377
C++实现的表达式求值: http://blog.csdn.net/he_qiao/article/details/8710495
Python实现的带UI的表达式计算器:http://blog.csdn.net/he_qiao/article/details/20162553