java实现计算机界面

要求

设计一个计算器界面,至少要包含如下按键:0,1,2,3,4,5,6,7,8,9,+,-,*,/,=,C(清零)。

java实现

package com.ming;
import javax.swing.*;
import static java.awt.BorderLayout.*;
import java.awt.*;

public class Calculator{
	
	public static void main(String[] args) {
		JFrame jf=new JFrame("计算器");
		JPanel jp1=new JPanel();
		jp1.add(new JTextField(30));
		jf.add(jp1,NORTH);
		JPanel jp2=new JPanel();//设置Panel,使用GridLayout布局管理器
		jp2.setLayout(new GridLayout(4,4,6,6));
		String[] name={"7","8","9","/","4","5","6","*",
					   "1","2","3","-","0","C","=","+"};
		for(int i=0;i

结果截图

java实现计算机界面_第1张图片

你可能感兴趣的:(java实现计算机界面)