为什么在文本框里点击回车才会显示菜单栏?怎么解决?

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_y⁡x","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”中加入菜单项

}

}
救救孩子吧,各位大佬们(磕头)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值