当我编写一个简单的程序时,我遇到了这个:
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
Display* display;
int main(){
display = XOpenDisplay("");
if (display == NULL) {
printf("Cannot connect\n");
exit (-1);
}
else{
printf("Success!\n");
XCloseDisplay(display);
}
}
Run Code Online (Sandbox Code Playgroud)
仅供参考,我安装了xQuartz.我使用"g ++ -o ex ex.cpp -L/usr/X11R6/lib -lX11"命令编译该程序.
据我所知,两个库都包含超过90%的相同精确代码.当我在我的示例程序中声明它们时,没有任何魔法发生.我真的不明白这些libs的区别,即使它们位于单独的目录中.有人可以为我分解吗?
另外:我尝试在sys/socket.h上面声明linux/in.h,编译器嗡嗡作响,"找不到sa_family_t的指定限定列表",这意味着sa_family_t没有在linux/in.h的范围内定义,如果以这种方式打电话......
然后我为netinet/in.h尝试了同样的事情,好吧,无论声明在哪里,它都能正常工作.
我试图用java awt绘制一个矩形,并通过鼠标拖动使其与鼠标光标一起旋转.
当我测试它时,矩形旋转速度非常快.
我的矩形():
private Rectangle2D rec = new Rectangle2D.Float(x0,y0,w,h);
AffineTransform recTrans = new AffineTransform();
int pivotX = x0+w/2, pivotY = y0+h;
// (0,0) is at the top-left corner
Run Code Online (Sandbox Code Playgroud)
我的paintComponent():
public void paintComponent(Graphics g) {
Graphics2D graph = (Graphics2D) g;
graph.translate(x,y);
graph.transform(recTrans);
graph.fill(rec);
graph.setColor(Color.blue);
graph.draw(rec);
}
Run Code Online (Sandbox Code Playgroud)
我的鼠标拖动事件:
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
previousX = e.getX();
previousY = e.getY();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
currentX = e.getX();
currentY = e.getY();
double angle1 = …Run Code Online (Sandbox Code Playgroud)