我到处搜索,有大量的文档,但都是令人困惑的,一半的测试代码不起作用,所以我问。制作 jlabel 的最简单方法是什么,设置它的位置(使用整数或维度),并将其添加到 JFrame
package com.notelek.notify;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Gui {
public static void main(String[] args){
}
public static void notify(String line1, String line2, String imagepath, int style){
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int swidth = width - 320;
JFrame notification = new JFrame();
notification.setSize(new Dimension(320,64));
notification.setLocation(swidth, 0);
notification.setUndecorated(true);
notification.setVisible(true);
JPanel main = new JPanel();
JLabel notifyline1 = new JLabel();
notifyline1.setText("test");
notifyline1.setLocation(0, 0);
main.add(notification);
}
}