자바 개발 시스템 트 레이 기반 응용
실행 효과:
========================================================================
다음은 코드 부분:
========================================================================
/tray/src/com/b510/tray 트 레이/DesktopCapture.java
package com.b510.tray ;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class DesktopCapture extends JFrame implements ActionListener {
/**
* 1. 2. BUG 3.
*/
private static final long serialVersionUID = 1L;
// JButton confirm;
// BufferedImage desktopImg;
MyTray tray;
boolean iconed = false;
public DesktopCapture() {
super("EasyCapture");
init();
// "-" ,
addWindowListener(new WindowAdapter() {
public void windowIconified(WindowEvent e) {
iconed = true;
setVisible(false);
}
// "X" ,
// , , ,
public void windowClosing(WindowEvent e) {
int option = JOptionPane.showConfirmDialog(DesktopCapture.this,
" ?", " :", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
iconed = true;
setVisible(false);
} else {
System.exit(0);
}
}
});
pack();
setSize(350, 230);
setLocation(500, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setResizable(false);
setVisible(true);
}
void init() {
tray = new MyTray(DesktopCapture.this);
}
//
public void capture() {
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
DesktopCapture desk = new DesktopCapture();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void actionPerformed(ActionEvent e) {
}
}
/tray/src/com/b510/tray托盘/MyTray.java
package com.b510.tray ;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class MyTray implements ActionListener, MouseListener {
private Image icon;//
private TrayIcon trayIcon;
private SystemTray systemTray;//
private DesktopCapture frame; //
private PopupMenu pop = new PopupMenu(); //
private MenuItem capture = new MenuItem("capture");
private MenuItem show = new MenuItem("open");
private MenuItem exit = new MenuItem("exit");
public MyTray(DesktopCapture frame) {
this.frame = frame;
// icon = Toolkit.getDefaultToolkit().getImage("./images/xiaomai.png");
icon = new ImageIcon(this.getClass().getClassLoader().getResource(
"image/xiaomai.png")).getImage();
if (SystemTray.isSupported()) {
systemTray = SystemTray.getSystemTray();
trayIcon = new TrayIcon(icon, " -EasyCapture", pop);
pop.add(capture);
pop.add(show);
pop.add(exit);
try {
systemTray.add(trayIcon);
} catch (AWTException e1) {
e1.printStackTrace();
trayIcon.addMouseListener(this);
}
}
trayIcon.addMouseListener(this);
show.addActionListener(this);
exit.addActionListener(this);
capture.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == show) {
frame.iconed = false;
frame.setVisible(true);
frame.setExtendedState(JFrame.NORMAL);
} else if (e.getSource() == capture) {
frame.capture();
} else {
System.exit(0);
}
}
// ����¼�
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1 && e.getButton() != MouseEvent.BUTTON3) {
frame.capture();
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 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에 따라 라이센스가 부여됩니다.