十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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();
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。