Java 编写的简单的 QQ 登录界面
代码:
.
// An highlighted block
package BiAn0528;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LogUI {
//主函数
public static void main(String [] a) {
System.out.print("Hello Java!");
LogUI logUI = new LogUI();
logUI.ShowUI();//调用显示窗口的方法
}
//窗口
public void ShowUI() {
// new JFrame
JFrame logFrame = new JFrame();
logFrame.setTitle("登陆界面 作者:distiny");
logFrame.setSize(400, 350);
logFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//进程关闭
//布局--流式
FlowLayout f1 = new FlowLayout();
logFrame.setLayout(f1);
//按钮
JButton btn = new JButton("登录");
//图片
ImageIcon img = new ImageIcon("C:\\Users\\王晓\\Desktop\\JAVA\\Nanjie\\QQ.png");
JLabel imgJla = new JLabel(img);
//文字
String namestr = "账号: " ;
String pwdstr = "密码: " ;
JLabel nameJla = new JLabel(namestr);
JLabel pwdJla = new JLabel(pwdstr);
//输入框
JTextField nameField = new JTextField();
JPasswordField pwdField = new JPasswordField();
//组件
Dimension dim = new Dimension(320,30);
nameField.setPreferredSize(dim);
pwdField.setPreferredSize(dim);
//将组件添加到窗体上
logFrame.add(imgJla);
logFrame.add(nameJla);
logFrame.add(nameField);
logFrame.add(pwdJla);
logFrame.add(pwdField);
logFrame.add(btn);
//设置可视化
logFrame.setVisible(true);
}
}
成文仓促,若有不当之处,欢迎交流~