标题:请在我原来的代码上添加简单计算器的加减乘除功能(简单点的,java)
取消只看楼主
yangzhe7878
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-12-27
 问题点数:0 回复次数:0 
请在我原来的代码上添加简单计算器的加减乘除功能(简单点的,java)
package Firstproject;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class SimpleCounter {
    public void Counter(){
        JFrame jf=new JFrame("SimpleCounter");
        JPanel shuru=new JPanel();//创建输入框面板
        JTextField txet=new JTextField();
        JPanel qingchu=new JPanel();
        JPanel shuzi=new JPanel();
    //输入框文本的基本设置
        txet.setText(".0");
        txet.setColumns(20);
        txet.setHorizontalAlignment(SwingConstants.RIGHT);
        shuru.add(txet);
        txet.setEditable(false);
        jf.add(shuru,BorderLayout.NORTH);
    //清楚 2个按钮的基本设置
        JButton C=new JButton();
        JButton Bs=new JButton();
        C.setText("清零");
        Bs.setText("退格");
        qingchu.add(C);
        qingchu.add(Bs);
        jf.add(qingchu,BorderLayout.CENTER);
    //网格数字的基本设置
        GridLayout g=new GridLayout(4,4,5,5);
        shuzi.setLayout(g);
        jf.add(shuzi,BorderLayout.SOUTH);
        String[][] ButtonNames={{ "1","2","3","+",},{"4","5","6","-",},{"7","8","9","*"},{"0",".","=","/",}};
        JButton[] inputButtonNames=new JButton[20];
        for(int hang=0;hang<ButtonNames.length;hang++){
            for(int lie=0;lie<ButtonNames.length;lie++){
                inputButtonNames[hang*5+lie]=new JButton(ButtonNames[hang][lie]);
                inputButtonNames[hang*5+lie].setName(hang+""+lie);
                shuzi.add(inputButtonNames[hang*5+lie]);
               
            }
        }

    //窗体的基本设置
        jf.setSize(250, 250);
        jf.setLocation(500, 200);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        SimpleCounter sc=new SimpleCounter();
        sc.Counter();
    }
   

}
搜索更多相关主题的帖子: 计算器 package public import java 
2016-01-09 13:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-460961-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.200088 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved