窗口学习

import java.awt.*;
import java.applet.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField; 
public class Addition 
{
    public static void main(String[] args) 
    {
        JFrame frame=new JFrame("请登录");
        frame.setSize(500, 300);
        frame.getContentPane( ).setBackground(Color.BLACK);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        JPanel panle=new JPanel( );
        frame.add(panle);
        placeComponents(panle);
        Font font=new Font("TimesRoman",Font.BOLD,15);
    }
    
    static void placeComponents(JPanel panle)
    {
        panle.setLayout(null);
        
        JLabel lable =new JLabel("用户名");
        lable.setBounds(90,80, 80, 25);
        panle.add(lable);
        
        JTextField textfield=new JTextField(20);
        textfield.setBounds(150,80,150, 25);
        panle.add(textfield);
        
        JLabel password=new JLabel("密码");
        password.setBounds(90, 110, 80, 25);
        panle.add(password);
        
        JPasswordField passwordTxt=new JPasswordField(20);
        passwordTxt.setBounds(150,110,150,25);
        panle.add(passwordTxt);
        
        JLabel codeLable=new JLabel("验证码");
        codeLable.setBounds(90, 140, 80, 25);
        panle.add(codeLable);
        
        JTextField codeText=new JTextField(20);
        codeText.setBounds(150, 140, 50, 25);
        panle.add(codeText);
        
        Font font=new Font("TimesRoman",Font.BOLD,15);
        JLabel code=new JLabel(makeCode());
        code.setBounds(200, 140,80, 25);
        panle.add(code);
        
        JButton button1=new JButton("确定");
        button1.setBounds(90, 180, 150, 30);
        panle.add(button1);
    
        JButton button2=new JButton("快速注册");
        button2.setBounds(90,220,150,30);
        panle.add(button2);
    }
    
    public static String makeCode( )
    {
        String code="";
        for(int i = 0 ; i < 4 ; i ++)
        {
            int intVal = (int)(Math.random() * 26 + 97);
            code = code + (char)intVal;
        }
        return code;
    }
}

 

posted @ 2020-12-15 16:16  derek&cosmo  阅读(109)  评论(0)    收藏  举报