溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

java實(shí)現(xiàn)計(jì)算器

發(fā)布時(shí)間:2020-05-28 16:07:45 來(lái)源:億速云 閱讀:264 作者:鴿子 欄目:編程語(yǔ)言

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 = {
{ "標(biāo)準(zhǔn)型", "科學(xué)型", "程序員", "統(tǒng)計(jì)信息", "歷史信息", "數(shù)字分組", "基本", "單位轉(zhuǎn)換",
"日期計(jì)算", "工作表" }, { "復(fù)制(C)", "粘貼(P)", "歷史記錄" },
{ "查看幫助(V)", "關(guān)于計(jì)算器(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);//測(cè)量長(zhǎng)寬和間距
}
jb.setMarigin(new java.awt.Insets(0,0,0,0) );
thsi.add(jb);
{

}{
}
}
this.setTitle("計(jì)算器");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("計(jì)算器");
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();

}

}

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI