资源简介
整合了网上的一些JFrame添加背景,添加移动,无边框的代码,设计的还算好看吧!
代码片段和文件信息
package javaEX8;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JlayeredPane;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.ImageIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.Font;
import javax.swing.UIManager;
public class LowBTalk extends Jframe {
private ImageIcon background;
public static void main(String[] args) {
LowBTalk frame = new LowBTalk();
frame.setVisible(true);
}
private static final long serialVersionUID = 1L;
//用于处理拖动事件,表示鼠标按下时的坐标,相对于Jframe
int xOld = 0;
int yOld = 0;
public LowBTalk() {
getContentPane().setLayout(null);
//处理拖动事件
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
xOld = e.getX();
yOld = e.getY();
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
int xOnScreen = e.getXOnScreen();
int yOnScreen = e.getYOnScreen();
int xx = xOnScreen - xOld;
int yy = yOnScreen - yOld;
LowBTalk.this.setLocation(xx yy);
}
});
background = new ImageIcon(“img/HackerBack.jpg“);// 背景图片
setSize(background.getIconWidth() background.getIconHeight());
//JlayeredPane用于添加两个图层的,一个用于背景,一个用于界面
JlayeredPane layeredPane = new JlayeredPane();
layeredPane.setBounds(0 0 background.getIconWidth()background.getIconHeight());
getContentPane().add(layeredPane);
//背景Panel
JPanel bgPanel = new JPanel();
bgPanel.setBounds(0 0 background.getIconWidth() background.getIconHeight());
layeredPane.add(bgPanel);
- 上一篇:SNMP管理站开发-java实现
- 下一篇:android studio 天气预报
评论
共有 条评论