一:本文主要介绍用java画图写一个用户登录界面,其中包括的功能效果有:
1:新用户的创建
2:将用户信息保存在txt文件,文件路径设置为D:\\map\\Secret1.txt,路径可以自行修改
3:切换用户
4:更改密码
5:可以做到访问电脑硬盘更换头像
:共由8个.java文件构成
1:MainFrame
作用:主窗体
代码:
package TEST;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import TEST.objectContainer;
import TEST.ChangePasswordFrame;
import TEST.ImageBufferFrame;
import TEST.ReadTxtFile;
import TEST.Register;
import TEST.login;
public class MainFrame extends JFrame{
static JButton JB1,JB2;
static JMenu JB3;
JMenuBar menubar=new JMenuBar();
JMenuItem ChangeUser,ChangePassword,Exit;
static ChangePasswordFrame CPF;
static login log;
static Register reg;
static ReadTxtFile read;
static ImageBufferFrame IBF=null;
public MainFrame(){
setSize(500,300);
setLocation(400,400);
JB1=new JButton("用户登录");
JB2=new JButton("选择头像");
JB3=new JMenu("");
JB1.setBounds(10, 10,100 ,100);
JB2.setBounds(10, 10,100 ,100);
JB3.setBounds(10, 10,100 ,100);
ChangeUser=new JMenuItem("切换用户");
ChangePassword=new JMenuItem("修改密码");
Exit=new JMenuItem("退出当前账户");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(menubar,BorderLayout.NORTH);
menubar.add(JB1);
menubar.add(JB2);
menubar.add(JB3);
JB3.add(ChangeUser);
JB3.add(ChangePassword);
JB3.add(Exit);
JB2.setVisible(false);
JB3.setVisible(false);
ChangeUser.addActionListener(new changerUser());
ChangePassword.addActionListener(new changePassword());
Exit.addActionListener(new UserLoad());
JB1.addActionListener(new UserLoad());
JB2.addActionListener(new ChangeLogo());
}
class UserLoad implements ActionListener{
public void actionPerformed(ActionEvent e)
{
objectContainer.frame.log.setVisible(true);
objectContainer.frame.log.f1.setText("");
objectContainer.frame.log.f2.setText("");
}
}
class ChangeLogo implements ActionListener{
public void actionPerformed(ActionEvent e)
{
JB2.setText("");
try {
objectContainer.frame.IBF=new ImageBufferFrame();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
class changerUser implements ActionListener{
public void actionPerformed(ActionEvent e)
{
objectContainer.frame.log.setVisible(true);
objectContainer.frame.log.f1.setText("");
objectContainer.frame.log.f2.setText("");
}
}
class changePassword implements ActionListener{
public void actionPerformed(ActionEvent e)
{
</