java Border/BorderLayout 实现GroupBox

在java中没有找到类似于C++中的groupbox,搜了一下才知道是要用borderlayout和border实现的。

做笔记如下:

Code:
  1. import java.awt.*;   
  2. import javax.swing.border.*;   
  3. import java.awt.event.*;   
  4. import javax.swing.*;   
  5.   
  6. public class Test5 {   
  7.     public static void main(String[] args) {   
  8.         SmallFrame sf = new SmallFrame();   
  9.         sf.setVisible(true);   
  10.     }   
  11. }   
  12.   
  13. class SmallFrame extends JFrame {   
  14.     Container p;   
  15.     JLabel tip = new JLabel("请输入学号:");   
  16.     JTextField stuNoText = new JTextField();   
  17.     JPanel viewPane = new JPanel();   
  18.     JButton ok = new JButton("确定");   
  19.     JButton reset = new JButton("重置");   
  20.     public SmallFrame() {   
  21.         super("按学号查询");   
  22.         setBounds(200100350280);   
  23.         setResizable(false);   
  24.         setDefaultCloseOperation(EXIT_ON_CLOSE);   
  25.         p = getContentPane();   
  26.         p.setLayout(null);   
  27.         tip.setBounds(702010020);   
  28.         tip.setForeground(Color.red);   
  29.         stuNoText.setBounds(1552010020);   
  30.         p.add(tip);   
  31.         p.add(stuNoText);   
  32.         ok.setBounds(90606020);   
  33.         ok.setForeground(Color.green);   
  34.         p.add(ok);   
  35.         reset.setBounds(180606020);   
  36.         reset.setForeground(Color.green);   
  37.         p.add(reset);   
  38.         //关键代码块   
  39.         TitledBorder tb = new TitledBorder(BorderFactory.createLineBorder(new Color(25500)),"查询结果");   
  40.         tb.setTitleColor(Color.blue);   
  41.         viewPane.setBorder(tb);   
  42.         viewPane.setLayout(null);   
  43.         JLabel stuNoLabe = new JLabel("学号:");   
  44.         stuNoLabe.setBounds(801308020);   
  45.         stuNoLabe.setForeground(new Color(3413934));   
  46.         p.add(stuNoLabe);   
  47.         JTextField stuNoTextf = new JTextField();   
  48.         stuNoTextf.setBounds(1501309020);   
  49.         p.add(stuNoTextf);   
  50.         JLabel stuNameLabe = new JLabel("姓名:");   
  51.         stuNameLabe.setBounds(801608020);   
  52.         stuNameLabe.setForeground(new Color(3413934));   
  53.         p.add(stuNameLabe);   
  54.         JTextField nameTextf = new JTextField();   
  55.         nameTextf.setBounds(1501609020);   
  56.         p.add(nameTextf);   
  57.         JLabel stuAgeLabe = new JLabel("年龄:");   
  58.         stuAgeLabe.setBounds(801908020);   
  59.         stuAgeLabe.setForeground(new Color(3413934));   
  60.         p.add(stuAgeLabe);   
  61.         JTextField ageTextf = new JTextField();   
  62.         ageTextf.setBounds(1501909020);   
  63.         p.add(ageTextf);   
  64.            
  65.         viewPane.add(new JButton("HKJJ"));   
  66.         viewPane.setBounds(18100310141);   
  67.         p.add(viewPane);   
  68.     }   
  69. }  

上面程序的效果图:

                                 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值