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()==添加){
}
}
}
|