- 浏览: 139642 次
- 性别:
- 来自: 宁波
文章分类
最新评论
-
每天一首喜欢的歌:
这是用什么软件做的
java仿迅雷下载 -
ma546659141:
厉害
java仿迅雷下载 -
shreo_2007:
完美运行.很强大.很好的学习资源
java仿迅雷下载 -
盖世英雄_1988:
我去,楼主你为什么这么吊,太强大了。。支持楼主,顶顶顶顶。。。 ...
java仿迅雷下载 -
WLLT:
niu 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 ...
java仿迅雷下载
package free; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.Robot; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.event.MouseInputAdapter; import twaver.TWaverUtil; import com.sun.awt.AWTUtilities; public class ShellWindowBorderPane extends JPanel { private Color windowTitleColor = FreeUtil.DEFAULT_TEXT_COLOR; private Color inactiveRootColor = TWaverUtil.getRandomColor();// new // Color(66, // 187, // 125); private Color activeRootColor = TWaverUtil.getRandomColor();// new Color(94, // 215, 170); private Image activeTitleShadow = null; private Image inactiveTitleShadow = null; private class BorderLabel extends JLabel { protected Image image = null; protected Image inactiveImage = null; public BorderLabel(String imageURL) { this.image = getImage(imageURL, true); this.inactiveImage = getImage(imageURL, false); } @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; Window window = getFrameWindow(); if (window.isActive()) { g2d.drawImage(image, 0, 0, getWidth(), getHeight(), this); } else { g2d.drawImage(inactiveImage, 0, 0, getWidth(), getHeight(), this); } } } private static final int TITLE_HEIGHT = 30; private static final int BORDER_SIZE = 7; private Image topImage = getImage("window_border_top.png", true); private Image topImageInactive = getImage("window_border_top.png", false); private JButton btnClose = createWindowButton("window_border_close", "Close"); private JButton btnMax = createWindowButton("window_border_max", "Maximize"); private JButton btnMin = createWindowButton("window_border_min", "Minimize"); private JLabel lbTop = new JLabel() { { this.setLayout(new BorderLayout()); JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); buttonPane.setOpaque(false); buttonPane.add(btnMin); buttonPane.add(btnMax); buttonPane.add(btnClose); this.add(buttonPane, BorderLayout.EAST); this.addMouseListener(new MouseAdapter() { private Robot robot = null; private boolean isClickLogo(MouseEvent e) { // check whether click logo image. Rectangle imageBounds = null; int logoWidth = logo.getWidth(null); int logoHeight = logo.getHeight(null); if (isWindowMaxmized()) { imageBounds = new Rectangle(2, 4, logoWidth, logoHeight); } else { imageBounds = new Rectangle(2, 2, logoWidth, logoHeight); } return imageBounds.contains(e.getPoint()); } @Override public void mouseReleased(MouseEvent e) { // popup menu. if (isClickLogo(e)) { if (robot == null) { try { robot = new Robot(); } catch (Exception ex) { ex.printStackTrace(); } } if (robot != null) { // send a "ALT+SPACE" keystroke to popup window // menu. robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); } } } @Override public void mouseClicked(MouseEvent e) { if (isClickLogo(e)) { if (e.getClickCount() > 1) { System.exit(0); } } } }); } @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); } @Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Frame window = getFrameWindow(); int leadingX = 2; Image image = topImage; if (!window.isActive()) { image = topImageInactive; } if (isWindowMaxmized()) { leadingX = 4; g2d.drawImage(image, 0, -2, getWidth(), getHeight() + 2, this); } else { g2d.drawImage(image, 0, 0, getWidth(), getHeight(), this); } // 1. title shadow. g2d.setFont(FreeUtil.FONT_14_BOLD); if (activeTitleShadow == null) { activeTitleShadow = FreeUtil.createWindowTitleShadowImage(g2d, "xxxx2222222柜员综合业务系统ddd", true); inactiveTitleShadow = FreeUtil.createWindowTitleShadowImage( g2d, "xxxx111111柜员综合业务系统ddd", false); } Image titleShadow = activeTitleShadow; if (!window.isActive()) { titleShadow = inactiveTitleShadow; } int shadowY = (titleShadow.getHeight(null) - TITLE_HEIGHT) / 2; g2d.drawImage(titleShadow, -10, -shadowY, null); // 2. title text. g2d.setColor(windowTitleColor); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawString("xxxx333333333柜员综合业务系统ddd", 25 + leadingX, 17); // 3. draw logo. g.drawImage(logo, leadingX, 4, null); // paint children: buttons. super.paint(g); } }; private JLabel lbBottom = new BorderLabel("window_border_bottom.png") { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, BORDER_SIZE); } }; private JLabel lbLeft = new BorderLabel("window_border_left.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, super.getPreferredSize().height); } }; private JLabel lbRight = new BorderLabel("window_border_right.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, super.getPreferredSize().height); } }; private JLabel lbLeftTop = new BorderLabel("window_border_left_top.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, TITLE_HEIGHT); } }; private JLabel lbRightTop = new BorderLabel("window_border_right_top.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, TITLE_HEIGHT); } }; private JLabel lbLeftBottom = new BorderLabel( "window_border_left_bottom.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, BORDER_SIZE); } }; private JLabel lbRightBottom = new BorderLabel( "window_border_right_bottom.png") { @Override public Dimension getPreferredSize() { return new Dimension(BORDER_SIZE, BORDER_SIZE); } }; private Image logo = TWaverUtil.getImage("/free/test/logo.png"); private Point lastPoint = null; private MouseInputAdapter mouseHandler = new MouseInputAdapter() { @Override public void mousePressed(MouseEvent e) { lastPoint = e.getLocationOnScreen(); } @Override public void mouseClicked(MouseEvent e) { handleClick(e); } @Override public void mouseDragged(MouseEvent e) { handleDrag(e); } @Override public void mouseMoved(MouseEvent e) { if (e.getSource() == lbTop) { if (e.getPoint().y < 5 && !isWindowMaxmized()) { lbTop.setCursor(Cursor .getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); } else { lbTop.setCursor(Cursor.getDefaultCursor()); } } } }; public ShellWindowBorderPane() { initSwing(); setupCursor(); } private void initSwing() { this.setLayout(new BorderLayout()); this.setOpaque(false); btnClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Frame frame = getFrameWindow(); if (frame instanceof JFrame) { JFrame jframe = (JFrame) frame; int operation = jframe.getDefaultCloseOperation(); if (operation == JFrame.EXIT_ON_CLOSE) { System.exit(0); } if (operation == JFrame.HIDE_ON_CLOSE) { jframe.setVisible(false); } if (operation == JFrame.DISPOSE_ON_CLOSE) { jframe.dispose(); } } } }); btnMax.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { maxWindow(); } }); btnMin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Frame frame = getFrameWindow(); if (frame.getExtendedState() != Frame.ICONIFIED) { frame.setExtendedState(Frame.ICONIFIED); } } }); JPanel topPane = new JPanel(new BorderLayout()); topPane.setOpaque(false); topPane.add(this.lbTop, BorderLayout.CENTER); topPane.add(this.lbLeftTop, BorderLayout.WEST); topPane.add(this.lbRightTop, BorderLayout.EAST); this.add(topPane, BorderLayout.NORTH); JPanel bottomPane = new JPanel(new BorderLayout()); bottomPane.setOpaque(false); bottomPane.add(this.lbBottom, BorderLayout.CENTER); bottomPane.add(this.lbLeftBottom, BorderLayout.WEST); bottomPane.add(this.lbRightBottom, BorderLayout.EAST); this.add(bottomPane, BorderLayout.SOUTH); this.add(this.lbLeft, BorderLayout.WEST); this.add(this.lbRight, BorderLayout.EAST); // setup mouse listeners. this.lbTop.addMouseMotionListener(mouseHandler); this.lbLeftTop.addMouseMotionListener(mouseHandler); this.lbLeftBottom.addMouseMotionListener(mouseHandler); this.lbRightTop.addMouseMotionListener(mouseHandler); this.lbRightBottom.addMouseMotionListener(mouseHandler); this.lbLeft.addMouseMotionListener(mouseHandler); this.lbRight.addMouseMotionListener(mouseHandler); this.lbBottom.addMouseMotionListener(mouseHandler); this.lbTop.addMouseListener(mouseHandler); this.lbLeftTop.addMouseListener(mouseHandler); this.lbLeftBottom.addMouseListener(mouseHandler); this.lbRightTop.addMouseListener(mouseHandler); this.lbRightBottom.addMouseListener(mouseHandler); this.lbLeft.addMouseListener(mouseHandler); this.lbRight.addMouseListener(mouseHandler); this.lbBottom.addMouseListener(mouseHandler); // window maxmized changed, change update cursor. this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { setupCursor(); } }); } private void setupCursor() { if (isWindowMaxmized()) { this.lbLeftTop.setCursor(Cursor.getDefaultCursor()); this.lbLeftBottom.setCursor(Cursor.getDefaultCursor()); this.lbRightTop.setCursor(Cursor.getDefaultCursor()); this.lbRightBottom.setCursor(Cursor.getDefaultCursor()); this.lbLeft.setCursor(Cursor.getDefaultCursor()); this.lbRight.setCursor(Cursor.getDefaultCursor()); this.lbBottom.setCursor(Cursor.getDefaultCursor()); } else { this.lbLeftTop.setCursor(Cursor .getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)); this.lbLeftBottom.setCursor(Cursor .getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)); this.lbRightTop.setCursor(Cursor .getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)); this.lbRightBottom.setCursor(Cursor .getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); this.lbLeft.setCursor(Cursor .getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); this.lbRight.setCursor(Cursor .getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); this.lbBottom.setCursor(Cursor .getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); } } private void handleClick(MouseEvent e) { if (e.getClickCount() > 1) { maxWindow(); } } private void maxWindow() { boolean max = isWindowMaxmized(); this.lbLeft.setVisible(max); this.lbRight.setVisible(max); this.lbBottom.setVisible(max); this.lbLeftTop.setVisible(max); this.lbRightTop.setVisible(max); this.lbLeftBottom.setVisible(max); this.lbRightBottom.setVisible(max); if (max) { getFrameWindow().setExtendedState(Frame.NORMAL); btnMax.setToolTipText("Maximize"); } else { getFrameWindow().setExtendedState(Frame.MAXIMIZED_BOTH); btnMax.setToolTipText("Normal"); } updateMaxButtonIcon(max); } private void handleDrag(MouseEvent e) { Point point = e.getLocationOnScreen(); if (point != null && lastPoint != null) { int xOffset = point.x - lastPoint.x; int yOffset = point.y - lastPoint.y; Frame window = this.getFrameWindow(); if (window.getExtendedState() != Frame.MAXIMIZED_BOTH) { JComponent component = (JComponent) e.getSource(); // if move window. if (component == lbTop) { // if resize top. if (component.getCursor().equals( Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR))) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; y += yOffset; height -= yOffset; window.setBounds(x, y, width, height); } else { // move window. window.setLocation(window.getLocation().x + xOffset, window.getLocation().y + yOffset); } } // if resize left top. if (component == this.lbLeftTop) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; x += xOffset; width -= xOffset; y += yOffset; height -= yOffset; window.setBounds(x, y, width, height); } // if resize left bottom. if (component == this.lbLeftBottom) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; x += xOffset; width -= xOffset; height += yOffset; window.setBounds(x, y, width, height); } // if resize right top. if (component == this.lbRightTop) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; width += xOffset; height -= yOffset; y += yOffset; window.setBounds(x, y, width, height); } // if resize right bottom. if (component == this.lbRightBottom) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; width += xOffset; height += yOffset; window.setBounds(x, y, width, height); } // if resize left. if (component == this.lbLeft) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; x += xOffset; width -= xOffset; window.setBounds(x, y, width, height); } // if resize right. if (component == this.lbRight) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; width += xOffset; window.setBounds(x, y, width, height); } // if resize bottom. if (component == this.lbBottom) { int width = window.getWidth(); int height = window.getHeight(); int x = window.getLocation().x; int y = window.getLocation().y; height += yOffset; window.setBounds(x, y, width, height); } } lastPoint = point; } } private boolean isWindowMaxmized() { Window window = TWaverUtil.getWindowForComponent(this); if (window instanceof Frame) { Frame frame = (Frame) window; return frame.getExtendedState() == Frame.MAXIMIZED_BOTH; } return false; } private Frame getFrameWindow() { Window window = TWaverUtil.getWindowForComponent(this); if (window instanceof Frame) { Frame frame = (Frame) window; return frame; } return null; } private JButton createWindowButton(String imageURL, String tooltip) { ImageIcon icon = FreeUtil.getImageIcon(imageURL + ".png"); ImageIcon iconPressed = FreeUtil .getImageIcon(imageURL + "_pressed.png"); ImageIcon iconRover = FreeUtil.getImageIcon(imageURL + "_rover.png"); JButton button = new JButton(icon); button.setPressedIcon(iconPressed); button.setRolloverIcon(iconRover); button.setVerticalAlignment(SwingConstants.CENTER); button.setOpaque(false); button.setBorder(null); button.setMargin(new Insets(0, 0, 0, 0)); button.setContentAreaFilled(false); button.setFocusPainted(false); button.setRolloverEnabled(true); button.setToolTipText(tooltip); return button; } private void updateMaxButtonIcon(boolean max) { String imageURL = "window_border_reset"; if (max) { imageURL = "window_border_max"; } ImageIcon icon = FreeUtil.getImageIcon(imageURL + ".png"); ImageIcon iconPressed = FreeUtil .getImageIcon(imageURL + "_pressed.png"); ImageIcon iconRover = FreeUtil.getImageIcon(imageURL + "_rover.png"); this.btnMax.setIcon(icon); this.btnMax.setPressedIcon(iconPressed); this.btnMax.setRolloverIcon(iconRover); } private Image getImage(String imageURL, boolean active) { Image image = FreeUtil.getImage(imageURL); if (active) { image = FreeUtil.createDyedImage(image, activeRootColor, true); } else { image = FreeUtil.createDyedImage(image, inactiveRootColor, true); } return image; } public void titleChanged(String title) { activeTitleShadow = null; inactiveTitleShadow = null; } public static void main(String[] args) { try { JFrame jf = new JFrame(); jf.setTitle("xxxx综合业务系统"); jf.setUndecorated(true); com.sun.awt.AWTUtilities.setWindowOpacity(jf, 0.9f); jf.setSize(new Dimension(400, 320)); ShellWindowBorderPane win = new ShellWindowBorderPane(); win.add(new JPanel()); jf.add(win); jf.setLocationRelativeTo(null); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }
发表评论
文章已被作者锁定,不允许评论。
-
swt table 自己造个轮子
2013-04-05 15:28 1155半年前的代码了,swt自带的table 感觉不是很漂亮,就 ... -
java仿迅雷下载
2012-04-22 21:07 10323package org.crazyit.fla ... -
java实现阿里旺旺界面
2012-04-22 17:02 3026package com.topthinking.exing ... -
java实现tab可关闭(chrome风格)
2012-04-22 17:05 4093* @author zhangtao packa ... -
java实现http代理服务
2012-04-22 17:03 22250package httpProxy; /***** ... -
设置可关闭的tab
2012-04-21 14:01 4354package demo.swing; imp ... -
java实现千千静听界面
2012-04-21 14:00 1644package com.tianlong.TTPla ... -
java渲染水晶按钮
2012-04-21 13:59 3205import java.awt.Color; ... -
Java获取系统软件安装列表
2012-04-21 13:58 3763/** * @author < ... -
测试Swing所有组件及其相应的事件
2012-04-21 13:57 1649import java.awt.BorderLayo ...
相关推荐
在Swing中实现透明窗体是一个常见的需求,特别是在设计现代、美观的应用程序时,透明效果往往可以增加视觉吸引力。 标题中的“Swing实现透明窗体”主要涉及以下几个知识点: 1. **AWT和Swing的区别**:在Java中,...
用Java实现透明和不规则窗体,区别Java awt和swing组件
透明窗体的实现主要依赖于`java.awt.Transparency`接口和`java.awt.Color`类的`getAlpha()`方法。通过设置特定组件的透明度值,可以创建出各种视觉效果,如模糊背景、动态过渡等。 在实际应用中,不规则窗体和透明...
实现控件在窗体内自由移动 控件不能移出窗体 窗体大小被设置成屏幕分辨率的大小 当控件Y坐标为0并且鼠标移出控件时,控件向上移动隐藏自身 鼠标移动到控件附近的时候,控件弹出 点击右键透明度增加,左键透明度降低...
"GradientTranslucentWindow.java"可能是一个示例,展示了如何使用颜色渐变来实现透明效果。在Java 7中,可以结合Java2D API来创建渐变色背景。`GradientPaint`或`LinearGradientPaint`类可以帮助我们创建线性渐变,...
本程序是java Swing的透明窗体的实现。
本压缩包“计算机软件-商业源码-实现透明窗体效果.zip”包含了实现这一效果的源代码,这将有助于开发者了解如何在自己的软件中实现类似功能。 透明窗体效果通常涉及到窗口的Alpha通道处理,Alpha通道是颜色中的一个...
透明窗体技术主要应用于桌面应用开发,例如使用Java进行的系统开发。Java提供了丰富的API来实现窗口的透明化效果,这使得开发者能够创建出更具视觉吸引力的应用程序。 在Java中,透明窗体的实现主要依赖于Java AWT...
### JDK 7.0 中实现半透明窗体 随着 Java 技术的不断发展和完善,Java 开发者们有了更多的选择来提升用户界面的美观性和功能性。JDK 7.0 的发布标志着 AWT (Abstract Windowing Toolkit) 正式支持半透明窗体,这为...
本示例将详细介绍如何利用Java实现JFrame透明窗体,帮助开发者创建出视觉效果更佳的应用程序。 首先,我们要知道Java标准库并不直接支持窗口的透明性设置。但是,从Java 6 Update 10开始,Sun Microsystems(后来被...
在Windows系统中,实现透明窗体主要依赖于GDI+(Graphics Device Interface Plus)或DirectX等图形库。GDI+提供了一种叫做Alpha混合的机制,通过设置像素的Alpha通道来实现不同程度的透明效果。Alpha值介于0和255...
在Windows上实现透明窗体,可能需要使用Win32 API中的`SetLayeredWindowAttributes()`函数。对于其他操作系统,如Linux或macOS,也需要相应的API或机制来实现透明。 在提供的文件列表中,我们看到了"META-INF"和...
为了实现透明窗体,你需要继承`javax.swing.JFrame`类,因为`JFrame`是Java Swing库中用于创建窗口的基础类。在类定义中,添加`extends JFrame`,并实现一个构造方法。在`main`方法中,实例化这个类,调用`...
实现透明窗体的技术通常涉及到图形设备接口(GDI)或更现代的DirectX、OpenGL等图形库,以及可能的Windows API调用。 在编程中,透明窗体的实现方法取决于使用的编程语言和框架。例如,在C#中,可以使用`Form....
1. **源代码**:如果这个“e”代表代码文件,那么可能包括了用各种编程语言(如C++, Java, Python等)实现透明窗体功能的示例代码。 2. **文档**:PDF或HTML形式的教程文档,详细解释了如何实现透明窗体效果,可能...
对于跨平台的编程语言如Java,我们可以使用Java AWT和Swing库来实现半透明窗体。通过调用`Window.setOpacity`方法,可以设置窗口的透明度。在Swing中,还可以使用`JComponent.setOpaque(false)`来让组件变得半透明,...
例如,可以设置JFrame的alpha值来实现透明背景,然后通过JLayeredPane添加前景和背景层,以实现动态背景效果。 此外,还可以使用Java的事件监听机制来处理用户的输入和点击行为。当用户点击登录按钮时,可以调用...