欢迎光临散文网 会员登陆 & 注册

qq

2023-06-09 15:16 作者:福乐哦  | 我要投稿

import javax.swing.JFrame; import java.awt.*; import java.awt.Color; import javax.swing.*; public class QQ extends JFrame{ JLabel L1,L2,L3,L4; JTextField input1; JPasswordField input2; JCheckBox fxk1,fxk2; JButton btn1; JPanel mb1,mb2,mb3,mb4,mb5,mb_c; public static void main(String[] args) { QQ a=new QQ(); } public QQ() { L1=new JLabel("QQ号码",JLabel.CENTER); L1.setFont(new Font("微软雅黑",Font.PLAIN,16)); L1.setForeground(new Color(0,0,0)); //设置字体颜色 L2=new JLabel("密码",JLabel.CENTER); L2.setFont(new Font("微软雅黑",Font.PLAIN,16)); L2.setForeground(new Color(0,0,0)); L3=new JLabel("找回密码"); L3.setFont(new Font("微软雅黑",Font.PLAIN,14)); L3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//鼠标移动到L3上变为手指 ImageIcon img1=new ImageIcon("image/label1.jpg"); img1.setImage(img1.getImage().getScaledInstance(550, 150,Image.SCALE_DEFAULT));//设置图片大小 L4=new JLabel(img1); input1=new JTextField(16); input2=new JPasswordField(16); fxk1=new JCheckBox("自动登录"); fxk1.setFont(new Font("微软雅黑",Font.PLAIN,14)); fxk2=new JCheckBox("记住密码"); fxk2.setFont(new Font("微软雅黑",Font.PLAIN,14)); btn1=new JButton(new ImageIcon("image/login.jpg")); mb1=new JPanel(); mb2=new JPanel(); mb3=new JPanel(); mb4=new JPanel(); mb5=new JPanel(); mb_c=new JPanel(); mb1.add(L4); mb_c.setLayout(new GridLayout(3,1)); mb2.add(L1); mb2.add(input1); mb3.add(L2); mb3.add(input2); mb4.add(fxk1); mb4.add(fxk2); mb4.add(L3); mb_c.add(mb2);mb_c.add(mb3);mb_c.add(mb4); mb5.add(btn1); this.setLayout(new BorderLayout()); this.add(mb1,BorderLayout.NORTH); this.add(mb_c,BorderLayout.CENTER); this.add(mb5,BorderLayout.SOUTH); this.setIconImage((new ImageIcon("image/QQ.png")).getImage()); this.setTitle("QQ"); this.setSize(550,430); this.setLocation(1000, 500); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } } import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class LoginFrame extends JFrame implements ActionListener {   private JLabel labelAccount, labelPassword;   private JTextField textFieldAccount;   private JPasswordField passwordField;   private JButton buttonLogin;   public LoginFrame() {     setTitle("QQ Login");     setSize(300, 150);     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     setLocationRelativeTo(null);     // 创建组件     labelAccount = new JLabel("Account:");     labelPassword = new JLabel("Password:");     textFieldAccount = new JTextField();     passwordField = new JPasswordField();     buttonLogin = new JButton("Login");     // 设置布局     setLayout(new GridLayout(3, 2));     // 添加组件     add(labelAccount);     add(textFieldAccount);     add(labelPassword);     add(passwordField);     add(new JPanel());     add(buttonLogin);     // 添加事件监听器     buttonLogin.addActionListener(this);     // 显示窗口     setVisible(true);   }   @Override   public void actionPerformed(ActionEvent e) {     if (e.getSource() == buttonLogin) {       // 登录验证代码       String account = textFieldAccount.getText();       String password = new String(passwordField.getPassword());       if (account.equals("admin") && password.equals("123456")) {         JOptionPane.showMessageDialog(null, "Login success!");         dispose(); // 关闭当前窗口         new FriendListFrame(); // 打开好友列表窗口       } else {         JOptionPane.showMessageDialog(null, "Account or password is incorrect!");       }     }   }   public static void main(String[] args) {     new LoginFrame();   } } import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class FriendListFrame extends JFrame implements ActionListener {   private JList listFriends;   private JButton buttonAdd, buttonDelete;   public FriendListFrame() {     setTitle("Friend List");     setSize(300, 200);     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     setLocationRelativeTo(null);     // 创建组件     listFriends = new JList<>(new String[]{"John", "Tom", "Lucy", "Jane"});     buttonAdd = new JButton("Add");     buttonDelete = new JButton("Delete");     // 设置布局     setLayout(new BorderLayout());     // 添加组件     add(new JScrollPane(listFriends), BorderLayout.CENTER);     JPanel panelButtons = new JPanel();     panelButtons.add(buttonAdd);     panelButtons.add(buttonDelete);     add(panelButtons, BorderLayout.SOUTH);     // 添加事件监听器     buttonAdd.addActionListener(this);     buttonDelete.addActionListener(this);     // 显示窗口     setVisible(true);   }   @Override   public void actionPerformed(ActionEvent e) {     if (e.getSource() == buttonAdd) {       String name = JOptionPane.showInputDialog("Input friend name:");       if (name != null && !name.trim().isEmpty()) {         DefaultListModel model = (DefaultListModel) listFriends.getModel();         model.addElement(name);       }     } else if (e.getSource() == buttonDelete) {       int[] indices = listFriends.getSelectedIndices();       if (indices.length > 0) {         DefaultListModel model = (DefaultListModel) listFriends.getModel();         for (int i = indices.length - 1; i >= 0; i--) {           model.remove(indices[i]);         }       }     }   }   public static void main(String[] args) {     new FriendListFrame();   } }

qq的评论 (共 条)

分享到微博请遵守国家法律