登陆界面java

登陆界面java_第1张图片
JOptionPane.showMessageDialog(null, “用户名或密码错误”);
这个也可以弹出对话框,更加方便

package lianxi;
import java.awt.*;
import javax.swing.*;

import org.omg.PortableServer.ServantRetentionPolicyValue;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.*;
public class get extends JFrame{
	public get() {
		JFrame f=new JFrame();
		Container c=getContentPane();
		setBounds(100, 100, 300, 200);
		c.setLayout(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		JLabel jl1=new JLabel("账号");
		JLabel jl2=new JLabel("密码");
		
		JTextField num=new JTextField(20);
		JPasswordField jp=new JPasswordField(20);
		jp.setEchoChar('^');
		
		JButton jb1=new JButton("登录");
		JButton jb2=new JButton("重置");
		jl1.setBounds(60, 20, 30, 20);
		jl2.setBounds(60, 50, 30, 20);
		num.setBounds(100, 20, 100, 20);
		jp.setBounds(100, 50, 100, 20);
		jb1.setBounds(90,80,60,20);
		jb2.setBounds(150,80,60,20);
		c.add(jl1);
		c.add(jl2);
		c.add(jb1);
		c.add(jb2);
		c.add(num);
		c.add(jp);
		//f.add(c);
		
		jb1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				JDialog jb=new JDialog(f,"sds", false);
			    Container c=getContentPane();
			    JLabel jl=new JLabel();
					if(num.getText().equals("mr")&&new String (jp.getPassword()).equals("mrsoft")){
						
					   jl.setText("登陆成功");
					    
					}
					else
						jl.setText("登陆失败");
					
					jb.add(jl);
				    jb.setBounds(1000,500,200,200);
				    jb.setVisible(true);
			}
		});
		jb2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				num.setText("");
				jp.setText("");
				
			}
		});
		
		setVisible(true);
}

	public static void main(String[] args) {
		get b=new get();
	}
}

你可能感兴趣的:(登陆界面java)