import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.LineBorder; import java.awt.*; /** * Created by Administrator on 2015/4/13 0013. * JPanel容器是一种 无边框 不能移动、放大、缩小或关闭的容器 * * * 思路分析 一般的登录窗口 可以简单的按照 BorderLayout * (边界布局)的使用划分为3个区域 北(panUP) * 中(panMiddle) * 南 (panSouth) * */ public class loginView{ public static void main(String[] args) { JFrame frame = new JFrame("登陆窗口"); frame.setSize(310,300); frame.setLayout(new BorderLayout()); //设置窗口布局为区域布局 JPanel panUp = new JPanel(); frame.add(panUp, BorderLayout.NORTH);//把panUP放在北边 JLabel lblNorth = new JLabel(); Icon icon = new ImageIcon("C:\\Users\\Administrator\\Desktop\\头像.jpg"); lblNorth.setIcon(icon); //图片放入北边 panUp.add(lblNorth); JPanel panMiddle = new JPanel(); Border border = new LineBorder(Color.RED); panMiddle.setBorder(border); frame.add(panMiddle, BorderLayout.CENTER); JLabel lblLogin = new JLabel("用户名"); lblLogin.setSize(50, 20); JTextField textLogin = new JTextField(""); textLogin.setColumns(20); textLogin.setSize(50, 20); JLabel lblPassword = new JLabel("密 码"); lblPassword.setSize(50, 20); JTextField textPassword = new JTextField(""); textPassword.setColumns(20); textPassword.setSize(50, 20); panMiddle.add(lblLogin); panMiddle.add(textLogin); panMiddle.add(lblPassword); panMiddle.add(textPassword); JPanel panSouth = new JPanel(); Border border2 = new LineBorder(Color.BLUE); panSouth.setBorder(border2); frame.add(panSouth, BorderLayout.SOUTH); JButton btnCon = new JButton("连接"); JButton btnExit = new JButton("退出"); JButton btnPro = new JButton("属性"); panSouth.add(btnCon); panSouth.add(btnExit); panSouth.add(btnPro); //frame.pack(); frame.setVisible(true); } }
效果图:
本文出自 “会搬砖的猴子” 博客,请务必保留此出处http://silianbo.blog.51cto.com/6627757/1632398
原文地址:http://silianbo.blog.51cto.com/6627757/1632398