Java JFrame/Frame 画不出图像
我已经试过了,图片可以加载,但就是画不出来。packagecylix.main;importjava.awt.Frame;importjava.awt.Graphics;...
我已经试过了,图片可以加载,但就是画不出来。
package cylix.main;
import java.awt.Frame;import java.awt.Graphics;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;
public class MainFrame extends Frame { public Thread painter = null; public Image bg = null;
public MainFrame() { super("4-Timespace 0.0.1 Origin");
painter = new PaintThread(this); bg = Toolkit.getDefaultToolkit().getImage("images/Solar.jpg");
this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { super.windowClosing(arg0); System.exit(0); } }); this.setSize(600, 600); this.setLocationRelativeTo(null); this.setResizable(false); }
public void launch() { this.setVisible(true); this.painter.start(); }
@Override public void paint(Graphics g) { super.paint(g); if(bg == null){ System.out.println("Cannot load image!!!"); }else{ g.drawImage(bg, 0, 0, this.getWidth(), this.getHeight(), null); } }
private Image iBuffer = null; private Graphics gBuffer = null;
@Override public void update(Graphics g) { if (iBuffer == null) { iBuffer = this.createImage(this.getWidth(), this.getHeight()); } gBuffer = iBuffer.getGraphics(); if (gBuffer != null) { this.paint(gBuffer); } else { this.paint(g); } gBuffer.dispose(); g.drawImage(iBuffer, 0, 0, null); }
public static void main(String[] args) { new MainFrame().launch(); }}这是项目结构:
求大神解答,在线等,急! 展开
package cylix.main;
import java.awt.Frame;import java.awt.Graphics;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;
public class MainFrame extends Frame { public Thread painter = null; public Image bg = null;
public MainFrame() { super("4-Timespace 0.0.1 Origin");
painter = new PaintThread(this); bg = Toolkit.getDefaultToolkit().getImage("images/Solar.jpg");
this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { super.windowClosing(arg0); System.exit(0); } }); this.setSize(600, 600); this.setLocationRelativeTo(null); this.setResizable(false); }
public void launch() { this.setVisible(true); this.painter.start(); }
@Override public void paint(Graphics g) { super.paint(g); if(bg == null){ System.out.println("Cannot load image!!!"); }else{ g.drawImage(bg, 0, 0, this.getWidth(), this.getHeight(), null); } }
private Image iBuffer = null; private Graphics gBuffer = null;
@Override public void update(Graphics g) { if (iBuffer == null) { iBuffer = this.createImage(this.getWidth(), this.getHeight()); } gBuffer = iBuffer.getGraphics(); if (gBuffer != null) { this.paint(gBuffer); } else { this.paint(g); } gBuffer.dispose(); g.drawImage(iBuffer, 0, 0, null); }
public static void main(String[] args) { new MainFrame().launch(); }}这是项目结构:
求大神解答,在线等,急! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询