用来遮字幕的程序

看日剧的时候,不想看到中文字幕。所以写了这个程序来遮住字幕。

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;

public class BlackFrame extends JFrame implements MouseListener,
MouseMotionListener {
private static final long serialVersionUID = 892335173996481654L;
private int x1;
private int y1;
private int x2;
private int y2;
private int direction;
private static final int NONE = -1;
private static final int TOP = 0;
private static final int LEFT = 1;
private static final int BOTTOM = 2;
private static final int RIGHT = 3;

public BlackFrame() {
this.setSize(400, 60);
this.setAlwaysOnTop(true);
this.setUndecorated(true);
this.setLayout(new BorderLayout());
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.getContentPane().setBackground(Color.BLACK);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
}

public void mouseClicked(MouseEvent e) {
// 鼠标右键
if (e.getButton() == MouseEvent.BUTTON3) {
System.exit(0);
}
}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {
}

public void mousePressed(MouseEvent e) {
x1 = e.getX();
y1 = e.getY();
if (x1 < 4) {
direction = LEFT;
} else if (x1 > this.getWidth() - 4) {
direction = RIGHT;
} else if (y1 < 4) {
direction = TOP;
} else if (y1 > this.getHeight() - 4) {
direction = BOTTOM;
} else {
direction = NONE;
}
}

public void mouseReleased(MouseEvent e) {
x2 = e.getX();
y2 = e.getY();

}

public void mouseDragged(MouseEvent e) {
x2 = e.getX();
y2 = e.getY();
if (direction == TOP) {
this.setSize(this.getWidth(), this.getHeight() - y2);
this.setLocation(this.getX(), this.getY() + y2);
} else if (direction == LEFT) {
this.setSize(this.getWidth() - x2, this.getHeight());
this.setLocation(this.getX() + x2, this.getY());
} else if (direction == BOTTOM) {
this.setSize(this.getWidth(), this.getHeight() + (y2 - y1));
y1 = y2;
y1 = y2;
} else if (direction == RIGHT) {
this.setSize(this.getWidth() + (x2 - x1), this.getHeight());
x1 = x2;
y1 = y2;
} else if (direction == NONE) {
this.setLocation(this.getX() + (x2 - x1), this.getY() + (y2 - y1));
}
}

public void mouseMoved(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (x < 4 || x > this.getWidth() - 4) {
this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
} else if (y < 4 || y > this.getHeight() - 4) {
this.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
} else {
this.setCursor(null);
}
}

/**
* @param args
*/
public static void main(String[] args) {
new BlackFrame().setVisible(true);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值