package FinalWork1;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Prototype_Calculater3 {
public static void main(String[] args) {
new Prototype_Calculater3();
}
boolean change = true;
final private int row = 7;
final private int col = 5;
public Prototype_Calculater3() {
JFrame f1 = new JFrame("标准计算器");
f1.setBounds(100, 40, 800, 1000);
f1.setDefaultCloseOperation(3);
f1.setLayout(null);
f1.setVisible(change);
JFrame f2 = new JFrame("科学计算器");
f2.setBounds(100, 40, 800, 1000);
f2.setDefaultCloseOperation(3);
f2.setLayout(null);
f2.setVisible(!change);
String[] buts1 = {"2nd","π","e","C","Back","x^2","1/x","|x|","exp","mod","√x","(",")","n!","÷","x^y","7","8","9","×",
"10^x","4","5","6","-","log","1","2","3","+","ln","+/-","0",".","="};
MyPanel f1p1 = new MyPanel(buts1);
f1p1.setBounds(0, 300, 800, 630);
f1p1.setBackground(Color.black);
f1.add(f1p1);
String[] buts2 = {"2nd","π","e","C","Back","x^3","1/x","|x|","exp","mod","3√x","(",")","n!","÷","y√x","7","8","9","×",
"2^x","4","5","6","-","log_yx","1","2","3","+","e^x","+/-","0",".","="};
MyPanel f2p1 = new MyPanel(buts2);
f2p1.setBounds(0, 300, 800, 630);
f2p1.setBackground(Color.black);
f2.add(f2p1);
MyPanel f1p2 = new MyPanel();
f1p2.setBounds(0, 0, 800, 300);
f1p2.setBackground(Color.black);
f1.add(f1p2);
MyPanel f2p2 = new MyPanel();
f2p2.setBounds(0, 0, 800, 300);
f2p2.setBackground(Color.black);
f2.add(f2p2);
//创建并添加菜单栏
JMenuBar jb1 = new JMenuBar();
f1.setJMenuBar(jb1);
//创建并添加所需的各种菜单项
JMenu menuTri = new JMenu("三角学"),menuFunc = new JMenu("f函数");
jb1.add(menuTri);
jb1.add(menuFunc);
f1.repaint();
f2.repaint();
}
}
class MyPanel extends JPanel{
private final int BLOCKWIDTH = 160;
private final int BLOCKHEIGHT = 90;
//用于创建按钮面板
public MyPanel(String[] buts) {
this.setLayout(null);
int index = 0;
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 5; j++) {
MyButton jb = new MyButton();
jb.setText(buts[index++]);
jb.setBounds(j*BLOCKWIDTH, i*BLOCKHEIGHT, BLOCKWIDTH, BLOCKHEIGHT);
this.add(jb);
}
}
}
//用于创建文本框面板
public MyPanel() {
JTextArea t1 = new JTextArea();
t1.setBounds(50, 100, 560, 40);
t1.setEditable(true);
this.add(t1);
t1.setVisible(true);
JTextArea t2 = new JTextArea();
t2.setBounds(50, 150, 660, 100);
t2.setEditable(true);
this.add(t2);
t2.setVisible(true);
}
}
class MyButton extends JButton{
public int i,j;
}
class MyJMenuBar extends JMenuBar{
public MyJMenuBar() {
// //创建并添加所需的各种菜单
// JMenu menuTri = new JMenu(“三角学”),menuFunc = new JMenu(“f函数”);
// this.add(menuTri);
// this.add(menuFunc);
//
// //在“三角学”菜单中加入“一般”和“hyp”菜单
// JMenu menuGeneral = new JMenu(“一般”),menuHyp = new JMenu(“hyp”);
// menuTri.add(menuGeneral);
// menuTri.add(menuHyp);
// //往“一般”和“hyp”中加入菜单项
}
}
救救孩子吧,各位大佬们(磕头)