• 2019JAVA第十次实验报告


    Java实验报告

    班级 计科二班 学号 20188442 姓名 吴怡君
    完成时间 2019.11.15
    评分等级

    实验代码

    package Domon9;
    
    import java.awt.Font;
    import java.awt.event.*;
    
    import javax.swing.*;
    
        class Logininterface {
    	
    	private JFrame frame = new JFrame("声明一个窗体对象");
    	private JButton submit = new JButton("登录按钮");
    	private JButton reset = new JButton("重置按钮");
    	private JLabel nameLab = new JLabel("用户名");
    	private JLabel passLab = new JLabel("密 码");
    	private JLabel infoLab = new JLabel("用户登录系统");
    	private JTextField nameText = new JTextField();
    	private JPasswordField passText = new JPasswordField();
    	
    	public  Logininterface(){
    		Font fnt = new Font("Serief",Font.BOLD,14);
    		infoLab.setFont(fnt);
    		submit.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent arg0){
    				if(arg0.getSource()==submit){
    					String n = nameText.getText();
    					String p = new String(passText.getPassword());
    					if(n.equals("Brent")&&p.equals("990903")) {
    						infoLab.setText("登录成功");
    	                }
    	                else if(n.equals("")) {
    	                	infoLab.setText("请输入用户名");
    	                }
    	                else if(p.equals("")) {
    	                	infoLab.setText("请输入密码");
    	                }
    	                else
    	                	infoLab.setText("用户名或密码错误");
    	            }
    	        }
    						
    		});
    		
    		 reset.addActionListener(new ActionListener() {
    		        public void actionPerformed(ActionEvent arg0) {
    		            if(arg0.getSource()==reset) {
    		            	nameLab .setText("");
    		                passLab.setText("");
    		                infoLab.setText("");
    		            }
    		        }
    		    });
    		 
    		 frame.setLayout(null);
    		 nameLab.setBounds(25, 25, 80, 40);
    		 passLab.setBounds(25, 50, 80, 40);
    		 infoLab.setBounds(25, 85, 240, 50);
    		 nameText.setBounds(85, 25, 120, 40);
    		 passText.setBounds(85, 50, 120, 40);
    		 submit.setBounds(185, 25, 80, 40);
    		 reset.setBounds(185, 50, 80, 40);
    		 
    		 frame.add(nameLab);
    		 frame.add(passLab);
    		 frame.add(infoLab);
    		 frame.add(nameText);
    		 frame.add(passText);
    		 frame.add(submit);
    		 frame.add( reset);
    		
    		 frame.setSize(300,150);
    		 frame.setVisible(true);
    		 
    		 
    	}
    	
    }
    
    package Domon9;
    
    public class test {
    
    	public static void main(String[] args) {
    		new Logininterface();
    	}
    
    }
    

    实验截图


    小题总结

    对于这道题目,主要是设置登录界面,所以首先得有窗体,然后在窗体里面用绝对布局器对里面的组件进行排列,然后就是必须要学会事件处理,这里面有很多方法可以帮助我们简单的设置出界面,总体来说,我觉得比较麻烦的就是那些英文字母了,有点让我眼花缭乱的感觉,不过基本代表的意思还是清晰的。

    课程总结:

    1.这周首先学习了一些其他的容器,通过这些容器我们可以更好的在页面中设置组件的摆放以及布局,然后就是学习了事件处理,主要学习了窗体事件以及动作事件,其中动作事件就是让按钮变得有意义,以后联系数据库之后将可以完整的去设置一个图形界面。
    2.就是这些类的一些方法:

  • 相关阅读:
    SDN课程阅读作业(2)
    2019 SDN上机第4次作业
    第11组 Alpha事后诸葛亮
    第11组 Alpha冲刺(6/6)
    第11组 Alpha冲刺(5/6)
    2019 SDN上机第3次作业
    2019 SDN阅读作业
    第11组 Alpha冲刺(4/6)
    第11组 Alpha冲刺(3/6)
    模式识别和机器学习、数据挖掘的区别与联系(转发)
  • 原文地址:https://www.cnblogs.com/521-PENG/p/11868586.html
Copyright © 2020-2023  润新知