界面和效果

转眼又上了一个星期课,我感觉的自己的差距越来越大,做作业相当吃力了,大概是因为平时练习不够。在这次的程序中,我选用了复选框JCheckBox并制作了登录界面,虽然比较简单,复选框都没有添加事件响应,输入用户名和密码也只能输入已经定义好的字符,如果输入为空或者输入非编辑好的文本,就会提示登录失败。却已经是十分努力的结果了。我一定会更加努力争取会有提升。

package abc;

import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Window;
import java.awt.event.*;

public class abc {
    
    private static ImageIcon background;
    public static void main(String[] args) {
        final JFrame frame = new JFrame("登录");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        JPanel northPanel = new JPanel(new GridLayout(2, 1));
        frame.add(northPanel, BorderLayout.NORTH);
        
        FlowLayout northfl = new FlowLayout();
        northfl.setVgap(10);
        northfl.setHgap(10);
        northfl.setAlignment(FlowLayout.LEFT);
        
        JPanel north1 = new JPanel(northfl);
        JPanel north2 = new JPanel(northfl);
        northPanel.add(north1);
        northPanel.add(north2);
        
        
        
        FlowLayout fl = new FlowLayout();
        fl.setHgap(50);
        JPanel southPanel = new JPanel(fl);
        frame.add(southPanel, BorderLayout.SOUTH);
        
        JLabel label1 = new JLabel("账号");
        //label1.setForeground(new Color(230, 230, 230));
        
        final JTextField input1 = new JTextField();
        input1.setColumns(20);
        
        //JLabel label2 = new JLabel("密码");
        
        //final JPasswordField input2 = new JPasswordField();
        //input2.setColumns(20);
        
        JCheckBox jcb = new JCheckBox("记住密码");
        JCheckBox jc2 = new JCheckBox("自动登录");
        JCheckBox jc3 = new JCheckBox("放弃登录");
        JCheckBox jc4 = new JCheckBox("忘记密码");
        JLabel label2 = new JLabel("密码");
        
        final JPasswordField input2 = new JPasswordField();
        input2.setColumns(20);
        JButton button1 = new JButton("登录");
        button1.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                if (input1.getText().equals("abc") && input2.getText().equals("123")) 
                    JOptionPane.showMessageDialog(frame, "登陆成功", "登陆成功", JOptionPane.INFORMATION_MESSAGE);
                else 
                JOptionPane.showMessageDialog(frame, "登陆失败", "登陆失败", JOptionPane.ERROR_MESSAGE);
            }
        });
        
        
        JButton button2 = new JButton("取消");
        button2.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                System.exit(0);
            }
        });

        input1.setBackground(Color.PINK);
        input2.setBackground(Color.GREEN);
    
        
//
        frame.getLayeredPane().add(label1,newInteger(Integer.MIN_VALUE));
        
        
        
        north1.add(label1);
        north1.add(input1);
        north2.add(label2);
        north2.add(input2);
        north2.add(jcb);
        north2.add(jc2);
        north2.add(jc3);
        north2.add(jc4);
        
        southPanel.add(button1);
        southPanel.add(button2);
        
        
        
        frame.pack();
        frame.setVisible(true);
        
    }

    private static Object newInteger(int minValue) {
        // TODO Auto-generated method stub
        return null;
    }

    private static void setIconImage(Image img) {
        // TODO Auto-generated method stub
        
    }

    private static void setLocation(int i, int j) {
        // TODO Auto-generated method stub
        
    }
}

 

posted @ 2016-03-18 19:19  14软一2014330128张芳  阅读(245)  评论(1编辑  收藏  举报