zoukankan      html  css  js  c++  java
  • 第十二周总结

    实验一:登录图形界面

    实验代码

    package Circle;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Modle {
    
        public static void main(String[] args) {
            JFrame frame=new JFrame("Welcome To MLDN");
            JButton submit=new JButton("登录");
            JButton reset=new JButton("重置");
            JLabel nameLabel=new JLabel ("用户名:");
            JLabel passLabel=new JLabel ("密码:");
            JLabel infoLab=new JLabel ("用户登录系统:");
            JTextField nameTest=new JTextField();
            JPasswordField passTest=new JPasswordField();
            
            submit.addActionListener(new ActionListener() {         //登录采用匿名内部类
                public void actionPerformed(ActionEvent argo) {
                    if(argo.getSource()==submit) {
                        String tname=nameTest.getText();
                        String tpass=new String(passTest.getPassword());
                        LoginCheck log=new LoginCheck(tname,tpass);
                        if(log.validate()) {
                            infoLab.setText("登录成功,记住密码");
                        }else {
                            infoLab.setText("登录失败!");
                        }
                    }
                    if (nameLabel.getText().equals("tanminjie") &&new String().equals("546788")){
                        JOptionPane.showMessageDialog(null, "登陆成功!");//弹出框判断是否成功
                    } 
                }
            }); 
            
           frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent arg0) {
                   System.exit(1);
                }
            }); 
            frame.setLayout(null);//使用绝对定位
            nameLabel.setBounds(5, 5, 60, 20);
            passLabel.setBounds(5, 30, 60, 20);
            infoLab.setBounds(5, 65, 220, 30);
            nameTest.setBounds(65, 5, 100, 20);
            passTest.setBounds(65, 30, 100, 20);
            submit.setBounds(165, 5, 60, 20);
            reset.setBounds(165, 30, 60, 20);
            
            frame.add(nameLabel);
            frame.add(passLabel);
            frame.add(nameTest);
            frame.add(passTest);
            frame.add(infoLab);
            frame.add(submit);
            frame.add(reset); 
            frame.setSize(280, 130);
            frame.setVisible(true);
        }
        }

    实验结果截图

     

     上机作业写错了,继续。

    package Circle;
    import java.io.*;
    public class D{
        public static void main(String[] args)throws IOException {
            String path1="F:"+File.separator+"Test"+File.separator+"demo1.txt";
            String path2="F:"+File.separator+"Test"+File.separator+"demo2.txt";
            File f1=new File(path1);
            File f2=new File(path2);
            
            InputStream input=new FileInputStream(f1);
            OutputStream out=new FileOutputStream(f2);
            
            byte b[]=new byte[(int)f1.length()];
            input.read(b);
            String m1=new String(b);
            char ah[]=m1.toCharArray();
            for(int i=0;i<ah.length;i++) {
                if(ah[i]>='a'&&ah[i]<='z'){
                    ah[i]=(char)(ah[i]-32);
                }
                else if(ah[i]>='A'&&ah[i]<='Z') {
                    ah[i]=(char)(ah[i]+32);
                }
            }
            String m2=new String(ah);
            byte a2[]=m2.getBytes();
            out.write(a2);
            
            try {
                input.close();
                out.close();
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
    
        }

    学习总结

    1.事件和监听器

    (1)事件类的继承关系

     (2)Java事件处理流程

     

     2.窗体事件:WindowListener接口的方法

     3.监听适配器

    4.动作事件及监听处理ActionListener接口方法

     5.用户登录操作

    (1)字符串比较时,把字符串放在前面。调用equals()方法。

    (2)使用绝对定位的方式进行版面的布局

  • 相关阅读:
    plusOne
    lengthOfLastWord
    maxSubArray
    countAndSay
    学生会管理系统-后端个人总结
    基于图结构实现地铁乘坐线路查询
    地铁线路项目简要分析
    Spring Boot 路由
    Spring Boot 项目配置的使用方法
    IDEA搭建Spring Boot项目
  • 原文地址:https://www.cnblogs.com/Markming/p/11865575.html
Copyright © 2011-2022 走看看