zoukankan      html  css  js  c++  java
  • 第二周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);
    

    }
    }

  • 相关阅读:
    Codeforces Gym 100015F Fighting for Triangles 状压DP
    Codeforces Gym 100015B Ball Painting 找规律
    Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
    Codeforces Gym 100231G Voracious Steve 记忆化搜索
    Codeforces Gym 100231F Solitaire 折半搜索
    Codeforces Gym 100231L Intervals 数位DP
    Codeforces Gym 100231B Intervals 线段树+二分+贪心
    Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何
    Codeforces Round #339 (Div. 2) B. Gena's Code 水题
    Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
  • 原文地址:https://www.cnblogs.com/lijie12/p/5293577.html
Copyright © 2011-2022 走看看