• swing版本计算器排版问题


     1  
     2 package Swing_exercise;
     3 
     4 import java.awt.*;
     5 
     6 import javax.swing.*;
     7 
     8 public class Calc extends JFrame {
     9 
    10 JPanel mainPanle, show, rightPanel;
    11 
    12 JTextField showIn;
    13 
    14 JButton[] jbs = new JButton[9];
    15 JButton zero = new JButton("0");
    16 JButton add1 = new JButton("+");
    17 JButton less = new JButton("-");
    18 JButton muit = new JButton("*");
    19 JButton div = new JButton("/");
    20 JButton point = new JButton(".");
    21 JButton equal = new JButton("=");
    22 
    23 Calc() {
    24 mainPanle = new JPanel(new GridLayout(4, 3, 10, 10));
    25 show = new JPanel(new FlowLayout());
    26 rightPanel = new JPanel(new GridLayout(4, 1, 10, 10));
    27 
    28 for (int i = 0; i < 9; i++) {
    29 jbs[i] = new JButton(String.valueOf(i + 1));
    30 
    31 }
    32 for (int i = 0; i < 9; i++) {
    33 mainPanle.add(jbs[i]);
    34 }
    35 mainPanle.add(point);
    36 mainPanle.add(zero);
    37 mainPanle.add(equal);
    38 
    39 showIn = new JTextField(20);
    40 show.add(showIn);
    41 
    42 add1.setForeground(Color.gray);
    43 add1.setBackground(Color.black);
    44 add1.setFont(new Font("黑体", Font.BOLD, 8));
    45 
    46 rightPanel.add(add1);
    47 rightPanel.add(less);
    48 rightPanel.add(muit);
    49 rightPanel.add(div);
    50 
    51 this.add(show, BorderLayout.NORTH);
    52 this.add(mainPanle);
    53 this.add(rightPanel, BorderLayout.EAST);
    54 
    55 this.setResizable(false);
    56 this.setVisible(true);
    57 this.setBounds(400, 300, 250, 320);
    58 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    59 
    60 }
    61 
    62 public static void main(String[] args) {
    63 new Calc();
    64 
    65 }
    66 
    67 }

    怎么在JFrame上 对左右两个JPanel的间距进行设置??

  • 相关阅读:
    Nginx自动加载配置文件方案
    git使用说明
    zabbix监控项截图整理
    Redhat 6.7 x64升级SSH到OpenSSH_7.4p1完整文档
    一次完整的浏览器请求流程
    JavaScript
    模块
    常用模块学习
    jenkins+Gitlab+maven+tomcat实现自动集成、打包、部署
    在线抠图网站速抠图sukoutu.com全面技术解析之canvas应用
  • 原文地址:https://www.cnblogs.com/ylfeiu/p/3365322.html
Copyright © 2020-2023  润新知