我的应用程序布局类似于:自定义JFrame(仅处理gui的创建),其中包含一个标准JPanel,其中包含一个自定义JPanel
在自定义的JPanel(称为MinimapPanel)内部,我更改了paint方法:
//in a constructor:
scaledTransform = new AffineTransform(); = new AffineTransform();
scaledTransform = new AffineTransform();
scaledTransform.scale(scaleAmount, scaleAmount);
//...
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setTransform(scaledTransform);
mapDrawer.paintMinimap(g, seatMap, miniViewHandler);//it just calls a bunch of fillRect
if (viewRect != null) {
g.setColor(new Color(255, 0, 0));
int x = viewRect.x;
int y = viewRect.y;
g.drawRect(x, y, Math.abs(viewRect.width), Math.abs(viewRect.height));
}
g2d.setTransform(plainTransform);
}
Run Code Online (Sandbox Code Playgroud)
如果我不应用trasform,或者缩放比例为1.0(无),则一切正常,但如果缩放,则每次JFrame重新绘制时,MinimapPanel都保持空白。
关于我可能做错了什么的任何想法?
我有一个矩阵A的NxM大小.我还有一个B包含索引对的数组,这些索引代表A我想要提取的行.
A = [ 1 2 3 %1
4 5 6 %2
7 8 9 %3
10 11 12 %4
13 14 15 %5
16 17 18]%6
B = [1 2
4 6]
Run Code Online (Sandbox Code Playgroud)
我想要C包含A1到2和4到6的行
C = [ 1 2 3 %1
4 5 6 %2
10 11 12 %4
13 14 15 %5
16 17 18]%6
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题而不进行迭代B?我试过C = A(B,:)但它不起作用(我没想到它......)