JAVA 窗口应用

package myproject;


import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class windows {
	public static void main(String[] args) {
		JFrame windows=new JFrame("登录窗口");
		windows.setVisible(true);
		windows.setSize(400, 250);
		Toolkit kit = Toolkit.getDefaultToolkit();    // 定义工具包
	     Dimension screenSize = kit.getScreenSize();   // 获取屏幕的尺寸
	    int screenWidth = screenSize.width/2;         // 获取屏幕的宽
	    int screenHeight = screenSize.height/2;       // 获取屏幕的高
	    int height = windows.getHeight();
	    int width = windows.getWidth();
	    windows.setLocation(screenWidth-width/2, screenHeight-height/2);
		windows.setResizable(true);
		windows.setLayout(null);
		JLabel label1=new JLabel("用户名:");
		label1.setBounds(50, 20, 50, 20);
		windows.add(label1);     
		JTextField texbook1=new JTextField();
		texbook1.setBounds(100, 20,150, 20);
		windows.add(texbook1);
		JLabel label2=new JLabel("密码:  ");
		label2.setBounds(50, 50, 50, 20);
		windows.add(label2);
		JPasswordField password1=new JPasswordField(10);
		password1.setEchoChar('*');
		password1.setBounds(100, 50,150, 20);
		windows.add(password1);
		JLabel label3=new JLabel("验证码:");
		label3.setBounds(50, 80, 50, 20);
		windows.add(label3);
		JTextField texbook2=new JTextField();
		texbook2.setBounds(100, 80,50, 20);
		windows.add(texbook2);
		Random rd=new Random();
		JLabel label4=new JLabel(Integer.toString(rd.nextInt(8999)+1000));
		label4.setBounds(200, 80, 40, 20);
		windows.add(label4);
		JButton button1=new JButton("确定");
		button1.setBounds(50, 120, 60, 20);
		windows.add(button1);
		JButton button2=new JButton("重置");
		button2.setBounds(120, 120, 60, 20);
		windows.add(button2);
		JButton button3=new JButton("取消");
		button3.setBounds(190, 120, 60, 20);
		windows.add(button3);
	}	
}

<img src="https://img-blog.youkuaiyun.com/20141120133819693?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbW96dW54/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值