java实现计算器
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
创新互联一直通过网站建设和网站营销帮助企业获得更多客户资源。 以"深度挖掘,量身打造,注重实效"的一站式服务,以做网站、网站设计、移动互联产品、全网营销推广服务为核心业务。十余年网站制作的经验,使用新网站建设技术,全新开发出的标准网站,不但价格便宜而且实用、灵活,特别适合中小公司网站制作。网站管理系统简单易用,维护方便,您可以完全操作网站资料,是中小公司快速网站建设的选择。
public class Myclass extends JFrame {
private JPanel jp1,jp2;
private JButton jb;
private JTextField display1, display2, display3;
private JMenuBar jmb;
private JMenu jm;
private JMenuItem jmi;
private final String[] firstmenu = { "查看(V)", "编辑(E)", "帮助(H)" };
private final String[][] secondMenu = {
{ "标准型", "科学型", "程序员", "统计信息", "历史信息", "数字分组", "基本", "单位转换",
"日期计算", "工作表" }, { "复制(C)", "粘贴(P)", "历史记录" },
{ "查看帮助(V)", "关于计算器(A)" } };
private final char[] Mnemonic = { 'V', 'E', 'H' };
private String buttonsName[]={"MC","MR","MS","M+","M-",
"←","CE","C","±","√",
"7","8","9","/","%",
"4","5","6","*","1/x",
"1","2","3","-","=",
"0",".","+"};
public Myclass(){
for (int i = 0; i < buttonsName.length; i++) {
jb = new JButton(buttonsName[i]);
if (i == 24) {
jb.setBounds(i % 5 (35 +7),65 + i /5 (29 + 7), 35, 65);
} else if (i ==25) {
jb.setBounds(i % 5 (35 +7),65 + i /5 (29 + 7), 77, 29);
} else if (i > 25) {
jb.setBounds(i % 5 (35 +7)+5+42,65 + i /5 (29 + 7), 35,29);
} else {
jb.setBounds(i % 5 (35 +7),65 + i /5 (29 + 7), 35, 29);//测量长宽和间距
}
jb.setMarigin(new java.awt.Insets(0,0,0,0) );
thsi.add(jb);
{
}{
}
}
this.setTitle("计算器");display2 = new JTextField("0");
display2.setBounds(12, 12, 190, 50);
display2.setFont(new Font("宋体", Font.BOLD, 26));
display2.setHorizontalAlignment(JLabel.RIGHT);
display2.setEnabled(false);
display2.setDisabledTextColor(Color.BLACK);
display2.setBackground(new Color(247, 250, 254));
this.add(display2);
this.setLayout(null);
this.setTitle("计算器");
this.setLocation(500, 200);
this.setSize(230, 320);
this.setBackground(new Color(217, 228, 241));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Myclass();
}
}
文章名称:java实现计算器
标题链接:http://scyanting.com/article/ipedsg.html