Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage("icon.png"));
final SystemTray tray = SystemTray.getSystemTray();
@SubscribeEvent
public void chatMSG(ClientChatReceivedEvent e) {
String msg = e.getMessage().getUnformattedText();
if (!msg.contains("<FTB_lag>") && (msg.contains("FTB_lag") || msg.contains("whispers to you"))) {
createAndASD(msg);
}
}
java.util.Timer timer;
class SayHello extends TimerTask {
public void run() {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tray.remove(trayIcon);
timer.cancel();
}
}
private void createAndASD(String msg) {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
return;
}
trayIcon.displayMessage("Minecraft", msg, TrayIcon.MessageType.INFO);
timer = new java.util.Timer();
timer.schedule(new SayHello(), 0, 4000);
//tray.remove(trayIcon);
}
val icon = TrayIcon(...)
val popup = PopupMenu()
fun init(){
...
val butt = MenuItem("Delete")
butt.addActionListener {
for (i in 1 until popup.itemCount) popup.remove(i) //обычный цикл от 1 до popup.itemCount
}
popup.add(butt)
icon.popupMenu = popup
require(SystemTray.isSupported()) // Просто пихни условие, если поддерживается, то строки ниже
val tray = SystemTray.getSystemTray()
tray.add(icon)
}
Когда получил сообщение:
fun receive() {
...
popup.add(event.message) //Строку как-нибудь впихнёшь
icon.image = новую картинку, если хочешь, а можно...
icon.displayMessage(...)
}