자바 데스크 톱 오른쪽 아래 창 효과 구현
수 정 된 코드 는 다음 과 같 습 니 다.
InfoUtil.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JDialog;
/**
* @author Administrator : , void show(" "," ") . InfoUtil tool
* = new InfoUtil(); tool.show(" "," ")
*/
public class InfoUtil {
private TipWindow tw = null; //
private JPanel headPan = null;
private JPanel feaPan = null;
private JPanel btnPan = null;
private JLabel title = null; //
private JLabel head = null; //
private JLabel close = null; //
private JTextArea feature = null; //
private JScrollPane jfeaPan = null;
private JButton sure = null;
private String titleT = null;
private String word = null;
private Desktop desktop = null;
// private SimpleDateFormat sdf = new
// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void init() {
// 300x180
tw = new TipWindow(300, 180);
headPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
feaPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
btnPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
title = new JLabel(" ");
head = new JLabel(titleT);
close = new JLabel(" x");
feature = new JTextArea(word);
jfeaPan = new JScrollPane(feature);
sure = new JButton(" ");
sure.setHorizontalAlignment(SwingConstants.CENTER);
// ,
tw.getRootPane().setBorder(
BorderFactory.createMatteBorder(1, 1, 1, 1, Color.white));
title.setPreferredSize(new Dimension(260, 26));
title.setVerticalTextPosition(JLabel.CENTER);
title.setHorizontalTextPosition(JLabel.CENTER);
title.setFont(new Font(" ", Font.PLAIN, 12));
title.setForeground(Color.black);
close.setFont(new Font("Arial", Font.BOLD, 15));
close.setPreferredSize(new Dimension(20, 20));
close.setVerticalTextPosition(JLabel.CENTER);
close.setHorizontalTextPosition(JLabel.CENTER);
close.setCursor(new Cursor(12));
close.setToolTipText(" ");
head.setPreferredSize(new Dimension(250, 35));
head.setVerticalTextPosition(JLabel.CENTER);
head.setHorizontalTextPosition(JLabel.CENTER);
head.setFont(new Font(" ", Font.PLAIN, 14));
head.setForeground(Color.black);
feature.setEditable(false);
feature.setForeground(Color.BLACK);
feature.setFont(new Font(" ", Font.PLAIN, 13));
feature.setBackground(new Color(255, 255, 255));
//
feature.setLineWrap(true);
jfeaPan.setPreferredSize(new Dimension(260, 100));
jfeaPan.setBorder(null);
jfeaPan.setBackground(Color.black);
tw.setBackground(Color.white);
// , JLabel
JLabel jsp = new JLabel();
jsp.setPreferredSize(new Dimension(300, 15));
sure.setPreferredSize(new Dimension(60, 30));
//
sure.setCursor(new Cursor(12));
// button
sure.setContentAreaFilled(false);
sure.setBorder(BorderFactory.createRaisedBevelBorder());
sure.setBackground(Color.gray);
// headPan.add(title);
headPan.add(head);
headPan.add(close);
feaPan.add(jsp);
feaPan.add(jfeaPan);
// feaPan.add(releaseLabel);
btnPan.add(sure);
headPan.setBackground(new Color(104, 141, 177));
feaPan.setBackground(Color.white);
btnPan.setBackground(Color.white);
tw.add(headPan, BorderLayout.NORTH);
tw.add(feaPan, BorderLayout.CENTER);
tw.add(btnPan, BorderLayout.SOUTH);
}
public void handle() {
//
desktop = Desktop.getDesktop();
sure.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
//
// try {
// desktop.browse(new URI("https://www.baidu.com"));
// } catch (Exception e1) {
// e1.printStackTrace();
// }
tw.close();
}
public void mouseEntered(MouseEvent e) {
sure.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
sure.setBorder(null);
}
});
//
close.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
tw.close();
}
public void mouseEntered(MouseEvent e) {
close.setBorder(BorderFactory.createLineBorder(Color.gray));
}
public void mouseExited(MouseEvent e) {
close.setBorder(null);
}
});
}
public void show(String titleT, String word) {
this.titleT = titleT;
this.word = word;
// time = sdf.format(new Date());
init();
handle();
tw.setAlwaysOnTop(true);
tw.setUndecorated(true);
tw.setResizable(false);
tw.setVisible(true);
tw.run();
}
public void close() {
tw.close();
}
}
class TipWindow extends JDialog {
private static final long serialVersionUID = 8541659783234673950L;
private static Dimension dim;
private int x, y;
private int width, height;
private static Insets screenInsets;
public TipWindow(int width, int height) {
this.width = width;
this.height = height;
dim = Toolkit.getDefaultToolkit().getScreenSize();
screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
this.getGraphicsConfiguration());
x = (int) (dim.getWidth() - width - 3);
y = (int) (dim.getHeight() - screenInsets.bottom - 3);
initComponents();
}
public void run() {
for (int i = 0; i <= height; i += 10) {
try {
this.setLocation(x, y - i);
Thread.sleep(50);
} catch (InterruptedException ex) {
}
}
// 6
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
e.printStackTrace();
}
close();
}
private void initComponents() {
this.setSize(width, height);
this.setLocation(x, y);
this.setBackground(Color.black);
}
public void close() {
x = this.getX();
y = this.getY();
int ybottom = (int) dim.getHeight() - screenInsets.bottom;
for (int i = 0; i <= ybottom - y; i += 10) {
try {
setLocation(x, y + i);
Thread.sleep(50);
} catch (InterruptedException ex) {
}
}
dispose();
}
}
main.java
public class main {
private final static String TITLE=" ";
public static void main(String[] args) {
InfoUtil test = new InfoUtil();
test.show(TITLE, " !");
}
}
효 과 는 다음 과 같 습 니 다:특별히 기록 합 니 다!
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.