62,628
社区成员
发帖
与我相关
我的任务
分享
import com.android.ninepatch.NinePatch;

public class PaneUI_9 extends JPanel {
NinePatch ninePatch;
public PaneUI_9(String path) {
ninePatch = loadNinePatch(path);
}
private NinePatch loadNinePatch(String path) {//这里是9图路径
InputStream stream = this.getClass().getResourceAsStream(path);
if (stream != null) {
try {
return NinePatch.load(stream, true, false);
} catch (IOException e) {
System.err.println("An error occurs during loading.");
e.printStackTrace();
return null;
}
} else {
System.err.println("Couldn't find the file: " + path);
return null;
}
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle clip = g2.getClipBounds();
ninePatch.draw(g2, clip.x, clip.y, clip.width, clip.height);
}
}
