import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JTextField;
public class ADSL extends JFrame {
private Container mainCon;
private JLabel imLab1, nameLab, pwdLab;
private JTextField nameTxt;
private JPasswordField pswTxt;
private JCheckBox forCB;
private JRadioButton meRa, anyRa;
private JButton coneBu, cancelBu, oBu, helpBu;
public ADSL() {
Toolkit to = Toolkit.getDefaultToolkit();
this.setTitle("连接 TT");
this.setBounds((int) (to.getScreenSize().width - 380) / 2, (int) (to.getScreenSize().height - 370) / 2, 380,
370);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.contains();
this.setVisible(true);
}
private void contains() {
this.mainCon = this.getContentPane();
// 把布局期关闭
this.setLayout(null);
// 设置标签
imLab1 = new JLabel();
this.imLab1.setIcon(new ImageIcon("jpg" + File.separator + "ADSL1.png"));
this.imLab1.setSize(350, 150);
this.imLab1.setLocation(15, 5);
this.mainCon.add(this.imLab1);
//可以用过html脚本来设置下划线
nameLab = new JLabel("<html>用户名(<u>U</u>) :</html>");
this.nameLab.setBounds(20, 160, 80, 20);
this.mainCon.add(nameLab);
pwdLab = new JLabel("<html>密 码(<u>P</u>) :</html>");
this.pwdLab.setBounds(20, 190, 80, 20);
this.mainCon.add(pwdLab);
nameTxt = new JTextField();
this.nameTxt.setBounds(110, 162, 200, 25);
this.mainCon.add(nameTxt);
// 设置密码框,做了一个鼠标监听时间。没有输入密码的时候,默认创建一个文本框,覆盖密码框
pswTxt = new JPasswordField();
this.pswTxt.setBounds(110, 187, 200, 25);
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JTextField nameTxt1 = new JTextField("[要更改保存的密码,请单击这里]");
nameTxt1.setFont(new Font("宋体", Font.ITALIC, 12));
nameTxt1.setBounds(110, 187, 200, 25);
mainCon.add(nameTxt1);
}
public void mouseEntered(MouseEvent e) {
JTextField nameTxt1 = new JTextField("[要更改保存的密码,请单击这里]");
nameTxt1.setFont(new Font("宋体", Font.ITALIC, 12));
nameTxt1.setBounds(110, 187, 200, 25);
mainCon.add(nameTxt1);
}
public void mouseExited(MouseEvent e) {
JTextField nameTxt1 = new JTextField("[要更改保存的密码,请单击这里]");
nameTxt1.setFont(new Font("宋体", Font.ITALIC, 12));
nameTxt1.setBounds(110, 187, 200, 25);
mainCon.add(nameTxt1);
}
});
this.mainCon.add(pswTxt);
JSeparator se = new JSeparator();
se.setBounds(20, 220, 340, 3);
mainCon.add(se);
// 设置复选框
forCB = new JCheckBox("<html>为下面用户保存用户名和密码(<u>S</u>) :</html>");
forCB.setBounds(20, 225, 240, 20);
mainCon.add(forCB);
// 设置单选框
meRa = new JRadioButton("<html>只是我(<u>N</u>) </html>");
meRa.setBounds(40, 245, 180, 20);
mainCon.add(meRa);
anyRa = new JRadioButton("<html>任何使用此计算机的人(<u>A</u>) </html>");
anyRa.setBounds(40, 265, 180, 20);
mainCon.add(anyRa);
// 把单选框加入小组
ButtonGroup bu = new ButtonGroup();
bu.add(meRa);
bu.add(anyRa);
// 分割线
JSeparator se1 = new JSeparator();
se1.setBounds(20, 288, 340, 3);
mainCon.add(se1);
// 设置4个按键
coneBu = new JButton("<html>连接(<u>C</u>) </html>");
coneBu.setBounds(21, 300, 80, 25);
coneBu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "没有网络连接不上!!");
}
});
mainCon.add(coneBu);
cancelBu = new JButton("取消");
cancelBu.setBounds(106, 300, 80, 25);
mainCon.add(cancelBu);
oBu = new JButton("<html>属性(<u>O</u>) </html>");
oBu.setBounds(191, 300, 80, 25);
mainCon.add(oBu);
helpBu = new JButton("<html>取消(<u>H</u>) </html>");
helpBu.setBounds(276, 300, 80, 25);
mainCon.add(helpBu);
}
}
简单的ADSL登录界面
最新推荐文章于 2021-07-31 15:40:41 发布