1_3_231164288张成伟.zip
立即下载
资源介绍:
1_3_231164288张成伟.zip
package xdfg;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class LoginForm extends JFrame {
public LoginForm() {
try {
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icon.png")));
setTitle("登录页面 - [示例应用]");
} catch (Exception e) {
e.printStackTrace();
}
setLocationRelativeTo(null);
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
BufferedImage img = ImageIO.read(new File("background.jpg"));
JLabel backgroundLabel = new JLabel(new ImageIcon(img));
add(backgroundLabel);
setContentPane(backgroundLabel);
setLayout(new FlowLayout());
} catch (IOException e) {
e.printStackTrace();
}
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new GridLayout(3, 2));
JLabel usernameLabel = new JLabel("用户名:");
usernameLabel.setFont(new Font("宋体", Font.PLAIN, 14));
usernameLabel.setBackground(Color.CYAN);
usernameLabel.setOpaque(true);
JTextField usernameField = new JTextField();
JLabel passwordLabel = new JLabel("密码:");
passwordLabel.setFont(new Font("宋体", Font.PLAIN, 14));
passwordLabel.setBackground(Color.CYAN);
passwordLabel.setOpaque(true);
JPasswordField passwordField = new JPasswordField();
JButton loginButton = new JButton("登录");
JButton cancelButton = new JButton("取消");
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(loginButton);
panel.add(cancelButton);
add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
LoginForm loginForm = new LoginForm();
loginForm.setVisible(true);
});
}
}