我正在尝试使用AWT创建UI.我想只使用图像和透明组件.现在我无法理解如何制作一个主窗口,它应该是一个自定义形状的PNG图像.图像中透明的所有区域都用黑色替换.这是我使用的代码:
public class Test {
static Image image;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
//switch to the right thread
image = ImageIO.read(Test.class.getClassLoader().getResource("resources/images/panel.png").openStream());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Frame frame = new Frame("Test");
frame.setUndecorated(true);
frame.setBackground(new Color(0,0,0,0));
frame.add(new BackGround(image,image.getWidth(frame),image.getHeight(frame)));
frame.pack();
frame.setSize(image.getWidth(frame), image.getHeight(frame));
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
);
}
private static class BackGround extends Component {
private Image img;
private int wid, hgt;
public BackGround(Image img, int wid, int …Run Code Online (Sandbox Code Playgroud) 我有2个Java应用程序.首先,我可以根据自己的意愿进行编辑,但稍后我会将其编译为机器代码.第二个我无法编辑,但我可以为它写一个插件.我需要让插件能够与第一个应用程序通信.通常只是相互发送字符串.流程的输入和输出流不是我的选择.我正在考虑使用tcp套接字客户端/服务器或作为缓冲区的文件.但这两种方式对我来说都有点难看,有人能提出一个更好的主意吗?
我需要传达我的Java应用程序和网站。由于某种原因,我选择使用HttpServer类。(我真的不懂PHP)。我看了这个问题:仅使用Java SE API的Java中的简单HTTP服务器
这是我使用的HttpHandler代码:
public class NexusHttpHandler implements HttpHandler{
private String response;
public NexusHttpHandler(String response){
this.response=response;
}
@Override
public void handle(HttpExchange he) throws IOException {
System.out.println("I am called!");
System.out.println(he.getRequestHeaders().keySet());
System.out.println(he.getRequestHeaders().values());
he.sendResponseHeaders(200, response.length());
OutputStream os = he.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,每次刷新页面都会两次调用“我被叫”。这是完整的输出:
I am called!
[Cache-control, Host, Accept-encoding, Connection, Accept-language, User-agent, Accept]
[[max-age=0], [localhost:8080], [gzip,deflate,sdch], [keep-alive], [ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4], [Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36], [text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]]
I am called!
[Host, Accept-encoding, Connection, Accept-language, User-agent, Accept]
[[localhost:8080], [gzip,deflate,sdch], …Run Code Online (Sandbox Code Playgroud)