盒子布局案例**登录页面login
2016-12-16 19:28
399 查看
打卡第二天
package com.cissst;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login extends JFrame {//盒子布局模式
private Box box1=Box.createHorizontalBox();
private Box box2=Box.createHorizontalBox();
private Box box3=Box.createHorizontalBox();
private Box box4=Box.createHorizontalBox();
private Box box5=Box.createVerticalBox(); //四个横着的盒子加到一个竖着的盒子里
private Icon icon=null; (1)继承类里面定义图片
private JLabel down=new JLabel();
private JLabel name=new JLabel("登 录:");
private JTextField myname=new JTextField();
private JLabel pass=new JLabel("密 码:");
private JPasswordField mypass=new JPasswordField(25);
private Button but1=new Button("登录");
private Button but2=new Button("注册");
public void init()
{
icon=new ImageIcon(this.getClass().getResource("/com/res/11.png")); (2)new一个image,,调用 (注意:在图片放在src下的com.ciss下的com.res
下,但是写成/com/res/11.png)
down.setIcon(icon); (3)将图片放到容器中,,此处是放入JLable 中
box1.add(Box.createVerticalStrut(20));
box1.add(Box.createHorizontalStrut(20));
box1.add(name);
box1.add(myname);
box1.add(Box.createHorizontalStrut(20));//添加横间距
box2.add(Box.createHorizontalStrut(20));
box2.add(pass);
box2.add(mypass);
box2.add(Box.createHorizontalStrut(20));
box3.add(Box.createHorizontalStrut(20));
box3.add(but1);
box3.add(Box.createHorizontalStrut(20));
box3.add(but2);
box3.add(Box.createHorizontalStrut(20));
box4.add(down);
box5.add(Box.createVerticalStrut(3));
box5.add(box1);
box5.add(Box.createVerticalStrut(6));
box5.add(box2);
box5.add(Box.createVerticalStrut(6));//添加纵间距
box5.add(box3);
box5.add(box4);
this.add(box5);
}
public Login()
{
super("login");
init(); //将各个部件加入到布局中是在构造函数里面,,此处只是放在init()中调用而已
Toolkit tool=Toolkit.getDefaultToolkit();//获取屏幕的大小
Dimension dim=tool.getScreenSize();//获取屏幕的大小
int width=(int)dim.getWidth();
int height=(int)dim.getHeight();
this.setSize(230,200);
this.setLocation((width-230)/2,(height-200)/2);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Login();
}
}
package com.cissst;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login extends JFrame {//盒子布局模式
private Box box1=Box.createHorizontalBox();
private Box box2=Box.createHorizontalBox();
private Box box3=Box.createHorizontalBox();
private Box box4=Box.createHorizontalBox();
private Box box5=Box.createVerticalBox(); //四个横着的盒子加到一个竖着的盒子里
private Icon icon=null; (1)继承类里面定义图片
private JLabel down=new JLabel();
private JLabel name=new JLabel("登 录:");
private JTextField myname=new JTextField();
private JLabel pass=new JLabel("密 码:");
private JPasswordField mypass=new JPasswordField(25);
private Button but1=new Button("登录");
private Button but2=new Button("注册");
public void init()
{
icon=new ImageIcon(this.getClass().getResource("/com/res/11.png")); (2)new一个image,,调用 (注意:在图片放在src下的com.ciss下的com.res
下,但是写成/com/res/11.png)
down.setIcon(icon); (3)将图片放到容器中,,此处是放入JLable 中
box1.add(Box.createVerticalStrut(20));
box1.add(Box.createHorizontalStrut(20));
box1.add(name);
box1.add(myname);
box1.add(Box.createHorizontalStrut(20));//添加横间距
box2.add(Box.createHorizontalStrut(20));
box2.add(pass);
box2.add(mypass);
box2.add(Box.createHorizontalStrut(20));
box3.add(Box.createHorizontalStrut(20));
box3.add(but1);
box3.add(Box.createHorizontalStrut(20));
box3.add(but2);
box3.add(Box.createHorizontalStrut(20));
box4.add(down);
box5.add(Box.createVerticalStrut(3));
box5.add(box1);
box5.add(Box.createVerticalStrut(6));
box5.add(box2);
box5.add(Box.createVerticalStrut(6));//添加纵间距
box5.add(box3);
box5.add(box4);
this.add(box5);
}
public Login()
{
super("login");
init(); //将各个部件加入到布局中是在构造函数里面,,此处只是放在init()中调用而已
Toolkit tool=Toolkit.getDefaultToolkit();//获取屏幕的大小
Dimension dim=tool.getScreenSize();//获取屏幕的大小
int width=(int)dim.getWidth();
int height=(int)dim.getHeight();
this.setSize(230,200);
this.setLocation((width-230)/2,(height-200)/2);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Login();
}
}
相关文章推荐
- LoginStatus登录页面默认值改变
- 如何布局登录页面
- login 登录页面(别小看这个页面在公司很有讲究的!昨天晚上熬夜写的)
- 用户手机客户端登录Login页面跳转到手机MobileLogin页面问题总结
- Login登录页面的制作流程(摘要)
- 登录页面(login)
- CCS bug之5: 已登录的用户点击Login.aspx时会出现"没有权限"的错误页面
- 如何布局登录页面
- 教程3:jsp和servlet配合的简单登录页面login.jsp
- 文件存储的实现-login登录案例2-sdcard
- 登录页面设计案例
- JY案例一:瀑布流布局页面
- Struts2.0里的过滤器interceptor之用户只可以访问Login.action与Register.action,访问其它.action的链接时,自动切换到登录页面
- login and signup 注册和登录tab页面
- 优秀网页设计:25个精美的登录页面设计案例
- 如何布局登录页面
- QuicklyBuildModel/Login.aspx.cs[快速类建模型登录页面代码]
- 优秀网页设计:25个精美的登录页面设计案例
- login页面按回车键(enter)登录功能
- wordpress主题开发教程手记:wp-login.php登录页面优化