通讯记录系统1(密码登陆窗体)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Login
{
        public static void main(String[] args)
        {
                LoginFrame loginFrame=new LoginFrame();
                loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                loginFrame.show();
        }
}
class LoginFrame extends JFrame
{
        public LoginFrame()
        {
                setTitle("通讯记录系统");
                setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
                Toolkit kit=Toolkit.getDefaultToolkit();
                Dimension screenSize=kit.getScreenSize();
                //为什么这里不能定义私有变量呢???
                int screenWidth=screenSize.width;
                int screenHeight=screenSize.height;
                setLocation(screenWidth/2-DEFAULT_WIDTH/2,screenHeight/2-DEFAULT_HEIGHT/2);
                Box b=Box.createVerticalBox();
                Container contentPane=getContentPane();
                //contentPane.setLayout(new GridLayout(5,4));
                //gridLayout=new GridLayout(4,1);
                //loginPanel=new JPanel(gridLayout);
                nameL=new JLabel("用户名:");
                nameT=new JTextField(8);
                passwordL=new JLabel("密 码:");
                passwordT=new JTextField(8);
                okB=new JButton("进入");
                canncelB=new JButton("退出");
                ///添加button事件
                okB.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent event){
                               
                        }
                }
                );
               
                canncelB.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent event){
                                System.exit(0);
                        }
                }
                );
                ///添加组建
                b.add(Box.createRigidArea(new Dimension(300,10)));
                nameP=new JPanel(new FlowLayout());
                nameP.add(nameL);
                nameP.add(nameT);
                b.add(nameP);
                b.add(Box.createRigidArea(new Dimension(300,10)));
                passwordP=new JPanel(new FlowLayout());
                passwordP.add(passwordL);
                passwordP.add(passwordT);
                b.add(passwordP);
                b.add(Box.createRigidArea(new Dimension(300,10)));
                buttonP=new JPanel(new FlowLayout());
                buttonP.add(okB);
                buttonP.add(canncelB);
                //no pointer
                b.add(buttonP);
                contentPane.add(b,BorderLayout.CENTER);
                //contentPane.add(buttonP,BorderLayout.SOUTH);
                //contentPane.add(loginPanel,BorderLayout.CENTER);
        }
                //窗口大小定义
                private int DEFAULT_WIDTH=300;
                private int DEFAULT_HEIGHT=200;
                //组件定义
                private JLabel nameL;
                private JLabel passwordL;
                private JTextField nameT;
                private JTextField passwordT;
                private JButton okB;
                //加组件的面板
                private JButton canncelB;
                private JPanel buttonP;
                private JPanel nameP;
                private JPanel passwordP;
                //private JPanel loginPanel;
                //private GridLayout gridLayout;
}      
               
               

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值