package com.flyingwind.tutorial;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;
import com.sun.awt.AWTUtilities;
public class TestWindow extends JFrame {
private GraphicsConfiguration translucencyCapableGC;//图形环境
private JPanel panel;//主面板
private Point origin; //用于移动窗体
private Image image;//头像图片
private ImageIcon icon;//标签图片
private Point location;
private Dimension size=new Dimension(260, 400);;//界面大小
private boolean isMax;
public boolean isMax() {
return isMax;
}
public void setMax(boolean isMax) {
this.isMax = isMax;
}
private SpringLayout springLayout_1;
TestWindow frame = this;
public TestWindow() {
isMax=false;//初始化界面最大化、最小化boolean值
this.origin=new Point(); //初始化偏移坐标
//初始或图片
try {
image=ImageIO.read(new File("95.gif"));
icon=new ImageIcon("away.gif");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setTitle("SIP");
setIconImage(image);
//获取系统图形环境
translucencyCapableGC = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
setSize(size);//设置窗体大小
setMinimumSize(size);//设置窗体最小时的大小
getContentPane().setLayout(new BorderLayout());
//定义颜色
final int R = 255;
final int G = 0;
final int B = 0;
//定义窗体颜色渐变
final Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 100),
getWidth(), getHeight(), new Color(R, G, B, 200), true);
//初始化窗体面板
panel = new JPanel() {
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(p);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setColor(new Color(0,0,0));
Shape shape = null;
shape = new RoundRectangle2D.Double(0, 0, frame.getWidth()-1, frame.getHeight()-1, 5.0D, 5.0D);//绘制窗体边框
g2d.draw(shape);
g2d.drawImage(image, 8, 35, 40, 40, null);
g2d.drawString("2010", 5, 15);
}
};
MouseInputListener listener = new MouseInputHandler();//添加窗体事件
addMouseListener(listener);
addMouseMotionListener(listener);
//设置窗体面板布局方式为弹簧布局
springLayout_1 = new SpringLayout();
panel.setLayout(springLayout_1);
getContentPane().add(panel);//将面板设置为主面板
setUndecorated(true);//去掉所有装饰:标题栏、大小、关闭
final JButton closeButton = new JButton();//关闭按钮
closeButton.setText("Close");
panel.add(closeButton);//将关闭按钮加入主面板
//关闭事件
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
setExtendedState(JFrame.EXIT_ON_CLOSE);
dispose();
//System.exit(0);
}
});
//最大化按钮
final JButton max=new JButton();
max.setText("Max");
panel.add(max);//将最大化按钮加入主面板
//最大化事件
max.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Rectangle rec = translucencyCapableGC.getBounds();//获取图形环境桌面大小
Insets d = Toolkit.getDefaultToolkit().getScreenInsets(translucencyCapableGC);//获取桌面工作区大小
frame.setSize(rec.width,rec.height-d.bottom);//设置窗体大小
//重新设定可见区域
setVisibleRegion(frame.getWidth(),frame.getHeight());
frame.repaint();
location=frame.getLocation();
frame.setLocation(0,0);
setMax(true);
}
});
//最小化按钮
final JButton min=new JButton();
min.setText("Min");
panel.add(min);//将最小化按钮加入主面板
//添加最小化事件
min.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (isMax()) {//判断是否是最大化状态
//如果是最大化状态则还原最小化时的坐标和值
frame.setSize(size);
//重新设定可见区域
setVisibleRegion(frame.getWidth(),frame.getHeight());
frame.repaint();
if (location != null) {
frame.setLocation(location);
}
setMax(false);
}else{
//正常状态最小化
setExtendedState(JFrame.ICONIFIED);
frame.hide();//隐藏任务栏
}
}
});
JPanel seachText=new JPanel();//中间面板
panel.add(seachText);
JLabel label=new JLabel();//下方图标
label.setIcon(icon);
panel.add(label);
//关闭按钮位置
springLayout_1.putConstraint(SpringLayout.EAST, closeButton, 230,
SpringLayout.WEST, panel);
//最大化按钮位置
springLayout_1.putConstraint(SpringLayout.EAST, max, 4,
SpringLayout.WEST, closeButton);
//最小化按钮位置
springLayout_1.putConstraint(SpringLayout.EAST, min, 4,
SpringLayout.WEST, max);
//中间面板位置
springLayout_1.putConstraint(SpringLayout.WEST, seachText, 5,
SpringLayout.WEST, panel);
springLayout_1.putConstraint(SpringLayout.NORTH, seachText, 100,
SpringLayout.NORTH, panel);
springLayout_1.putConstraint(SpringLayout.EAST, panel, 5, SpringLayout.EAST, seachText);
springLayout_1.putConstraint(SpringLayout.SOUTH, panel, 50, SpringLayout.SOUTH, seachText);
//图标位置
springLayout_1.putConstraint(SpringLayout.NORTH, label, 10, SpringLayout.SOUTH, seachText);
springLayout_1.putConstraint(SpringLayout.WEST, label, 20,SpringLayout.WEST, panel);
setCenter(seachText);//设置中间面板
//重新设定可见区域
setVisibleRegion(frame.getWidth(),frame.getHeight());
AWTUtilities.setWindowOpaque(frame, true);//设置窗体是否透明
center();
}
//设定可见区域
public void setVisibleRegion(int width,int height){
Shape shape = null;
shape = new RoundRectangle2D.Double(0, 0, width, height, 5.5D, 5.5D);
AWTUtilities.setWindowShape(frame, shape);
}
//设置中间面板,上下区域
public void setCenter(JPanel centerPanel){
GridBagLayout gd=new GridBagLayout();//网格布局
centerPanel.setLayout(gd);//设置中间面板布局方式为网格布局
GridBagConstraints c = new GridBagConstraints();//网格布局策略
JTextField field=new JTextField();//搜索栏
field.setText("搜索");
c.fill = GridBagConstraints.HORIZONTAL;//水平填充
c.gridx = 0;
c.gridy = 0;
centerPanel.add(field, c);
JPanel panel=new JPanel();
c.fill = GridBagConstraints.BOTH;//全部填充
c.weightx = 1.0;//设置横向填充比例
c.weighty = 0.8;//设置纵向填充比例
c.gridx = 0;
c.gridy = 1;
panel.setBackground(Color.BLUE);//设置背景颜色
centerPanel.add(panel, c);
setToolPanel(panel);
}
//设置好友显示区
public void setToolPanel(JPanel toolPanel){
GridBagLayout gd=new GridBagLayout();//网格布局
toolPanel.setLayout(gd);//设置中间面板布局方式为网格布局
GridBagConstraints c = new GridBagConstraints();//网格布局策略
JPanel tools=new JPanel();//左边工具栏
tools.setBackground(Color.CYAN);//设置背景颜色
c.fill = GridBagConstraints.VERTICAL;//设置为垂直填充
c.gridwidth=200;//设置宽度
c.gridx = 0;
c.gridy = 0;
toolPanel.add(tools, c)
Swing制作的QQ界面
4星 · 超过85%的资源 需积分: 10 185 浏览量
2010-04-22
13:39:58
上传
评论 4
收藏 4KB RAR 举报
光芒再现0394
- 粉丝: 95
- 资源: 7
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页