⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhuce.java

📁 秩序更改试题库
💻 JAVA
字号:
//完成
import java.io.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.BoxLayout.*;
import javax.swing.JOptionPane;
import javax.swing.filechooser.*;
import java.io.FileOutputStream;
public class Zhuce  extends Dialog implements ActionListener {
    Label nameLabel,passLabel,passlabel0,Photol,Geshi;
    Label Ge=new Label("   ");
    TextField nameText,passText1,passText2,Photo;
    Button Bzhuce,Bquxiao,Bliulan;
    FileDialog filedialog_load;
    public Zhuce(Frame f,String s,boolean b) {
        super(f,s,true);
        setBounds(300,300,300,210);
        nameLabel=new  Label("用户名 :");
        passLabel=new  Label("输入密码:");
        passlabel0=new Label("确认密码:");
        Photol=new Label("相片路径:");
        filedialog_load=new FileDialog(this,"打开文件话框",FileDialog.LOAD);
        filedialog_load.setVisible(false);
        Geshi=new Label("路径格式例c:\\\\a\\\\a.jpg,图片比例(宽:高=100:134)");
        nameText=new TextField(20);
        passText1=new TextField(20);
        passText2=new TextField(20);
        Photo=new TextField(14);
        Bzhuce=new Button("注册");
        Bquxiao=new Button("取消");
        Bliulan=new Button("浏览");
        setLayout(new FlowLayout());
        add(nameLabel);
        add(nameText);
        add(passLabel);
        add(passText1);
        add(passlabel0);
        add(passText2);
        passText1.setEchoChar('*');passText2.setEchoChar('*');
        add(Photol);add(Photo);add(Bliulan);
        Bliulan.addActionListener(this);
        add(Geshi);
        add(Bzhuce);Bzhuce.addActionListener(this);
        add(Ge);
        add(Bquxiao);Bquxiao.addActionListener(this);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==Bzhuce)
        {
            if(passText1.getText().equals(passText2.getText()))
            {File f = new File("data.txt");
                File jilu=new File("Uda.txt");
            try {
                BufferedReader Readline= new BufferedReader(new FileReader(jilu));
                RandomAccessFile out=new RandomAccessFile(jilu,"rw");
                RandomAccessFile endl=new RandomAccessFile(f,"rw");
                String Jiu=null;
                Jiu=Readline.readLine();
                StringTokenizer fenjie=new StringTokenizer(Jiu,"#");
                String get[] =new String[20];
                int i=0;boolean boo=true;
                if (f.exists())
                {
                    long length = f.length();
                    endl.seek(length);
                }
                if (jilu.exists())
                {
                    long length = out.length();
                    out.seek(length);
                }
                while(fenjie.hasMoreTokens())
                {
                    get[i]=fenjie.nextToken();
                    if(nameText.getText().equals(get[i]))
                    {
                        boo=false;
                        break;
                    }
                    i++;
                }
                if(boo==true)
                {
                    nameText.setEnabled(false);
                    passText1.setEnabled(false);
                    passText2.setEnabled(false);
                    Bzhuce.setEnabled(false);
                    Bquxiao.setEnabled(false);
                    Bliulan.setEnabled(false);
                    Photo.setEnabled(false);
                    setTitle("正在注册.....");
                    CopyFile();
                    endl.writeBytes("#"+nameText.getText()+" "+passText1.getText());
                    out.writeBytes("#"+nameText.getText());
                    JOptionPane.showMessageDialog(this,"注册成功!用户名:"+nameText.getText()
                                                  +" 密码:"+passText1.getText());//提示
                    RandomAccessFile newfile=new RandomAccessFile
                                  ("userdata/"+nameText.getText()+".txt","rw");
         endl.close();out.close();newfile.close();
                    setVisible(false);
                }
                else
                {
                    JOptionPane.showMessageDialog(this,"注册失败   用户名:"+nameText.getText()
                                                  +" 已存在!请重新注册!");
                }
            } catch (IOException IOe) {}
        }
        else
        {
            JOptionPane.showMessageDialog(this,"密码不一致!");
        }
    }
        if(e.getSource()==Bquxiao)
        {
            setVisible(false);
        }
        if(e.getSource()==Bliulan)
        {
            JOptionPane.showMessageDialog(this,"提示:图片名称格式只能为 .jpg !");
            filedialog_load.setVisible(true);
           String name=filedialog_load.getFile();
           if(name!=null)
           {
               String lujing=filedialog_load.getDirectory()+name;
               StringTokenizer fenjie=new StringTokenizer(lujing,"\\");
               String get[] =new String[200];
               String okk=fenjie.nextToken();
                while(fenjie.hasMoreTokens())
                {
                    okk=okk+"\\\\"+fenjie.nextToken();
                }
               Photo.setText(okk);
           }
        }
    }
    public void CopyFile() {
        try
        {
            FileInputStream input=new FileInputStream(Photo.getText().toString());
            FileOutputStream output=new FileOutputStream(".\\classes\\photo\\"+
                    nameText.getText()+".jpg");
            int in=input.read();
            while(in!=-1)
            {
                output.write(in);
                in=input.read();
            }
            input.close();output.close();
        }
        catch(IOException e)
        {
            JOptionPane.showMessageDialog(
                    this,"警告:您没有选择相片或相片路径错误!但是用户创建成功!");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -