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();
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。