界面制作模仿

启动界面

import java.awt.*;
import java.awt.event.*;
 
import javax.swing.*;
 
public class 启动 extends JFrame implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JTextField 用户;
	JPasswordField 密码;
	JButton 登录,注册,找回;
	public static void main(String args[]){
		try {
		    UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
		    UIManager.put("PasswordField.font",new Font("Verdana",Font.BOLD,12));
		    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		    /*
		    Font f = new Font("微软雅黑",Font.PLAIN,12);
			UIManager.put("TextField.font", f); 
			UIManager.put("Label.font", f);
			UIManager.put("ComboBox.font",f);
			UIManager.put("MenuBar.font",f);
			UIManager.put("ToolTip.font",f);
			UIManager.put("MenuItem.font",f);
			UIManager.put("Button.font",f);
			*/
		}catch (Exception e) {
			try {
				UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			}catch (Exception e2) {}
			JOptionPane.showMessageDialog(null, "加载皮肤失败,使用默认界面。","警告", JOptionPane.YES_NO_CANCEL_OPTION);
		}
		new 启动();
	}
	public 启动(){
 
		super("QQ2010");
		UIManager.put("PasswordField.echoChar",'●');
		setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		JLabel user,pass;
		JLabel banner = new JLabel(new ImageIcon(getClass().getResource("/banner.png")));
		banner.setBounds(0, 0, 324, 47);
		add(banner);
		user = new JLabel("账  号:");
		pass = new JLabel("密  码:");
		user.setBounds(15,  60, 140, 30);
		pass.setBounds(15, 110, 140, 30);
		用户 = new JTextField();
		密码 = new JPasswordField();
		密码.setEchoChar('●');
		用户.setBounds(90,  60, 220, 30);
		密码.setBounds(90, 110, 220, 30);
 
		add(user);
		add(pass);
		add(用户);
		add(密码);
		登录 = new JButton("登录");
		注册 = new JButton("注册");
		找回 = new JButton("找回密码");
		登录.setBounds(210, 155, 100, 30);
		注册.setBounds(110, 155, 100, 30);
		找回.setBounds(10, 155, 100, 30);
		add(注册);
		add(登录);
		add(找回);
		登录.addActionListener(this);
		注册.addActionListener(this);
		找回.addActionListener(this);
		setSize(324,220);
		setLocationRelativeTo(null);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==注册){
			setVisible(false);
			new 注册();
		}else if(e.getSource()==找回){
			setVisible(false);
			new 找回密码();
		}else if(e.getSource()==登录){
			setVisible(false);
			new 主界面();
		}
	}
}


注册界面

import java.awt.event.*;
import javax.swing.*;
 
public class 注册 extends JFrame implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JTextField 账号,昵称,邮箱;
	JPasswordField 密码1,密码2;
	JButton 注册,返回;
 
	public 注册(){
		super("QQ2010");
		setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
 
		int 宽度  = 220;
		int 高度 = 30;
 
		String label1[]={"注册提示:请仔细填写每项数据!","账  号:","昵  称:","邮  箱:","密  码:","重复密码:"};
		JLabel 标签[] = new JLabel[label1.length];
		for(int i=0;i<label1.length;i++){
			标签[i] = new JLabel(label1[i]);
			标签[i].setBounds(10, 5+i*30, 宽度, 高度);
			add(标签[i]);
		}
		String label2[]={"账号必须唯一","可任意填写","找回密码的凭据","请保证密码强度","确认密码"};
		JLabel 提示[] = new JLabel[label2.length];
		for(int i=0;i<label2.length;i++){
			提示[i] = new JLabel(label2[i]);
			提示[i].setBounds(315, 35+i*30, 宽度, 高度);
			add(提示[i]);
		}
 
		账号  = new JTextField();
		昵称  = new JTextField();
		邮箱  = new JTextField();
		账号.setBounds(90, 35, 宽度, 高度);
		昵称.setBounds(90, 65, 宽度, 高度);
		邮箱.setBounds(90, 95, 宽度, 高度);
 
		密码1 = new JPasswordField();
		密码2 = new JPasswordField();
		密码1.setEchoChar('●');
		密码2.setEchoChar('●');
		密码1.setBounds(90, 125, 宽度, 高度);
		密码2.setBounds(90, 155, 宽度, 高度);
 
		add(账号);
		add(昵称);
		add(邮箱);
		add(密码1);
		add(密码2);
		注册 = new JButton("注册");
		返回 = new JButton("返回");
		注册.setBounds( 90, 192, 100, 30);
		返回.setBounds(210, 192, 100, 30);
		add(注册);
		add(返回);
		注册.addActionListener(this);
		返回.addActionListener(this);
		setSize(420,255);
		setVisible(true);
		setLocationRelativeTo( null );
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==返回){
			setVisible(false);
			new 启动();
		}else if(e.getSource()==注册){
 
		}
	}
}



主界面

import java.awt.*;
import java.awt.event.*;
 
import javax.swing.*;
import javax.swing.tree.*;
public class 主界面 extends JFrame implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private Rectangle rect;
    private Point point;
    private Timer timer = new Timer(10, this);;
 
    JPanel main,login;
    JProgressBar 进度条;
    JFrame fr;
    JButton 关于,添加;
	public 主界面(){
		super("QQ2010");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setSize(250,630);
		fr = this;
 
		//登录界面
		login = new JPanel();
		login.setLayout(null);
		GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
		DisplayMode displayMode = graphicsDevice.getDisplayMode();
		setLocation(displayMode.getWidth()-50-250,50);
		//JLabel 图片 = new JLabel(new ImageIcon("logo.png"));
		JLabel 图片 = new JLabel(new ImageIcon(getClass().getResource("/logo.png")));
		JLabel 登录 = new JLabel("正在登录...");
		进度条 = new JProgressBar(JProgressBar.HORIZONTAL);
		进度条.setValue(20);
		图片.setBounds(68, 165, 100, 100);
		登录.setBounds(90, 230, 100, 100);
		进度条.setBounds(40, 290, 160, 20);
		login.add(图片,BorderLayout.NORTH);
		login.add(登录,BorderLayout.CENTER);
		login.add(进度条,BorderLayout.SOUTH);
		add(login);
 
 
		//主界面
		main = new JPanel();
		main.setLayout(null);
		JPanel 个人面板 = new JPanel();
		个人面板.setLayout(new BorderLayout(5,5));
		JLabel 头像 = new JLabel(new ImageIcon(getClass().getResource("/qq.png")));
		JLabel 名字 = new JLabel("<html>QQ:369339353 [在线]<br>耍下 www.shuax.com<br>版本:0.0.1 beta</html>");
		个人面板.add(头像,BorderLayout.WEST);
		个人面板.add(名字,BorderLayout.CENTER);
		个人面板.setBounds(0, 0, 250, 60);
		main.add(个人面板);
		DefaultMutableTreeNode root= new DefaultMutableTreeNode();
		DefaultMutableTreeNode parent;
 
		parent = new DefaultMutableTreeNode("我的好友");
		root.add(parent);
		for(int i=0;i<50;i++){
			parent.add(new DefaultMutableTreeNode("Cn_Harmony. "+i));
		}
 
		parent.add(new DefaultMutableTreeNode("..."));
		parent.add(new DefaultMutableTreeNode("止殇♂"));
		parent.add(new DefaultMutableTreeNode("街头,想着伱"));
		parent.add(new DefaultMutableTreeNode("埃及艳后"));
 
 
		parent = new DefaultMutableTreeNode("陌生人");
		root.add(parent);
		parent.add(new DefaultMutableTreeNode("那片天"));
		parent.add(new DefaultMutableTreeNode("^Q^"));
 
		JTree 好友= new JTree(root);
		好友.addMouseListener(
			new MouseAdapter(){
				public void mousePressed(MouseEvent e)
				{
					try {
						if(e.getClickCount()==2){
							DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((JTree) e.getSource()).getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
							Object userInfo = node.getUserObject();	
							 if (node.isLeaf()) {
							      JOptionPane.showMessageDialog(null, "你选择了好友:"+userInfo.toString());
							    //new 聊天窗口();
							 }
						}
					}catch(Exception e1){}
				}
			}
		);
		好友.setRootVisible(false);
		JScrollPane 滚动 = new JScrollPane(好友);
		滚动.setBounds(0, 60, 250, 500);
		main.add(滚动);
 
		JPanel info = new JPanel();
		info.setLayout(null);
		关于  = new JButton("关于");
		添加  = new JButton("添加好友");
		关于.setBounds(15, 0, 100, 30);
		添加.setBounds(135, 0, 100, 30);
		info.add(关于);
		info.add(添加);
		关于.addActionListener(this);
		添加.addActionListener(this);
		info.setBounds(0, 565, 250, 60);
		main.add(info);
		滚动().start();
        timer.start();
        setVisible(true);
	}
	public Thread 滚动()
    {
        return new Thread()
        {
			public void run(){
				int i = 进度条.getValue();
				int j = 0;
				while(j<90)
				{
					进度条.setValue(i++);
					if(i>=100) i=0;
					try {
						Thread.sleep(5);
					} catch (Exception e) {}
					j++;
				}
				login.setVisible(false);
				fr.add(main);
			}
        };
    }
    public boolean isPtInRect(Rectangle rect, Point point) {
        if (rect != null && point != null) {
            int x0 = rect.x;
            int y0 = rect.y;
            int x1 = rect.width;
            int y1 = rect.height;
            int x = point.x;
            int y = point.y;
 
            return x >= x0 && x < x1 && y >= y0 && y < y1;
        }
        return false;
    }
	public void actionPerformed(ActionEvent e){
		rect = new Rectangle(0, 0, getWidth(), getHeight());
        point = getMousePosition();
        if ((getLocationOnScreen().y < 0) && isPtInRect(rect, point)) {
            setLocation(getLocationOnScreen().x, 0);
        } else if (getLocationOnScreen().y > -2 && getLocationOnScreen().y < 2 && !(isPtInRect(rect, point))) {
            setLocation(getLocationOnScreen().x, 2 - getHeight());
        }
        if(e.getSource()==关于){
        	 JOptionPane.showMessageDialog(null, "程序开发:舒俊杰\n二〇一〇年四月二十一日","关于",JOptionPane.INFORMATION_MESSAGE);
		}else if(e.getSource()==添加){
		}
	}
}

完整可执行程序

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值