标题:SWing做个简单计算机界面的问题,请问大神为何我计算器的第五列的按钮出不来 ...
只看楼主
yangzhe7878
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-12-27
 问题点数:0 回复次数:2 
SWing做个简单计算机界面的问题,请问大神为何我计算器的第五列的按钮出不来啊求解
package Firstproject;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
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);
        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,0,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 
2015-12-30 12:06
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
得分:0 
看看布局,你那个生成按钮数组的地方好像有问题

一片落叶掉进了回忆的流年。
2015-12-30 12:49
yangzhe7878
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-12-27
得分:0 
回复 2楼 诸葛欧阳
有啥问题,具体请帮我改改
2015-12-30 13:37



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




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

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