第二周JAVA学习日志

从这周老师讲的东西中,我了解了许多以前不懂得东西。这周老师布置的作业,对我来说真的有点困难。通过上课的学习和下来翻书,勉强完成了一个登录界面的制作。这周学习的事件处理和swing组建以及swing组建的监听器,上课跟着老师做感觉还好,但是实际操作起来很难。希望以后通过老师的带领和自学,可以是我的JAVA学习更上一层。以下是我的登陆界面的程序就运行结果:
package denglujiemian;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class denglu {
public static void main(String[] args){
//创建窗体并设置窗体标题及关闭方式

JFrame frm = new JFrame("登录界面");
JLabel title = new JLabel("个人照片管理器");
title.setForeground(Color.BLUE);
title.setFont(new Font("宋体", Font.PLAIN, 36));
title.setBounds(260, 20, 292, 41);
frm.add(title);
//设置不使用布局管理器
frm.setLayout(null);

//创建用户标签并设置显示信息及起始位置与大小
JLabel userLabel = new JLabel();
userLabel.setText("用户名");
userLabel.setFont(new Font("楷体", Font.PLAIN, 24));
userLabel.setBounds(250, 100, 200, 100);

JLabel userLabel2 = new JLabel();
userLabel2.setText("密  码");
userLabel2.setFont(new Font("楷体", Font.PLAIN, 24));
userLabel2.setBounds(250, 200, 200, 50);

//创建用户名输入框,可编辑,并设置起始位置于大小
final JTextField userText = new JTextField();
userText.setBounds(350, 130, 200, 40);

final JPasswordField userText2 = new JPasswordField();
userText2.setBounds(350, 205, 200, 40);

//创建登录按钮,并设置起始位置与大小
JButton loginBtn = new JButton("登录");
loginBtn.setBounds(200,300,100,50);
loginBtn.setForeground(Color.RED);
JButton loginBtn2 = new JButton("退出");
loginBtn2.setBounds(500,300,100,50);
loginBtn2.setForeground(Color.RED);
loginBtn.addActionListener(new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent args) {
        // TODO Auto-generated method stub
        String account= userText.getText().toString(); 
        String mima = userText2.getText().toString(); 
        if(account.equals("1") && mima.equals("1")){
    
        JOptionPane.showMessageDialog(null,"登录成功","提示",JOptionPane.PLAIN_MESSAGE);
        } else {
        JOptionPane.showMessageDialog(null, "错误", "提示", JOptionPane.ERROR_MESSAGE);
        
        }
        
    }});
loginBtn2.addActionListener(new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        frm.setVisible(false);
    }
    
});
//将标签、输入框和按钮加入到窗体的容器中
frm.add(userLabel);
frm.add(userLabel2);
frm.add(userText);
frm.add(userText2);
frm.add(loginBtn);
frm.add(loginBtn2);
//设置窗体位置与大小并显示
frm.setBounds(600,300,800,500);
frm.setVisible(true);

}
}
902821-20160318204929787-1826094507.png

902821-20160318204943115-574860348.png

902821-20160318204959615-67589202.png

转载于:https://www.cnblogs.com/lijie12/p/5293577.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值