小编fos*_*man的帖子

绘制从角落偏移的图像的某些部分?

我正在使用各种精灵表加载到宇宙飞船中。Graphics.drawImage() 的文档说明参数是

boolean Graphics.drawImage(Image img,
   int dstx1, int dsty1, int dstx2, int dsty2,
   int srcx1, int srcy1, int srcx2, int srcy2,
   ImageObserver observer);
Run Code Online (Sandbox Code Playgroud)

但是,文档说dstx1和dsty2是左上角的坐标,当你使用dstx2和dsty2指定绘制的区域时,尺寸是(dstx2-dstx1)和(dsty2-dsty1)。除非我误解了该功能的工作原理,否则这似乎只会从角落加载图像的一部分。如何绘制未连接到左角的图像的一部分,以绘制精灵表的不同部分?

java graphics awt javax.imageio

2
推荐指数
1
解决办法
2826
查看次数

Frame.getContentPane().setBackground(Color.black)没有

我已经按照无数其他教程的建议来改变JFrame的背景颜色,但我没有运气.这是我的初始化和创建框架的代码

package frameTests;

import javax.swing.*;

import java.awt.*;


@SuppressWarnings("serial")
public class Foo extends JPanel {

public static void frameInit(Foo foobar){
    // window initialization
    JFrame frame = new JFrame("Spaceship Defenders!");
    frame.add(foobar);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
    frame.getContentPane().setBackground(Color.black);
    frame.setSize(500,500);
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);// center frame in screen.
}




public static void main(String[] args) throws InterruptedException{

    Foo bar = new Foo();
    frameInit(bar);

    }
}
Run Code Online (Sandbox Code Playgroud)

这是生成的框架,默认灰色背景

java swing colors jpanel jframe

1
推荐指数
1
解决办法
1711
查看次数

标签 统计

java ×2

awt ×1

colors ×1

graphics ×1

javax.imageio ×1

jframe ×1

jpanel ×1

swing ×1