【问题标题】:Add image from website to Frame in Java在Java中将图像从网站添加到框架
【发布时间】:2010-02-23 21:19:25
【问题描述】:

我正在尝试制作一个框架,我想从中添加来自网站的图像。

我是否将背景设置为图像?

import java.awt.*;
import java.net.*;

class NewFrame extends Frame {

  // Constructor.
  public NewFrame (int width, int height)
  {
    // Set the title and other frame parameters.
    this.setTitle ("Exercise 9.5");
    this.setResizable (true);
    this.setBackground (Color.cyan);
    this.setSize (width, height);

    // Show the frame.
    this.setVisible (true);
  }

  // Override paint():
  public void paint (Graphics g)
  {

  } 

} // End of class "NewFrame"

public class ex5 {

  public static void main (String[] argv)
  {
    NewFrame nf = new NewFrame (300, 250);
  }

}

【问题讨论】:

    标签: java swing awt


    【解决方案1】:

    你可以使用下面的

     // load the image once
     BufferedImage bi = ImageIO.read(new URL(imageLocAsString));
     // now in paint(Graphics g) do
     g.drawImage(bi, 0, 0, null);
    

    查看here了解更多信息。

    【讨论】:

    • 谢谢。这是我需要知道的
    猜你喜欢
    • 2016-12-08
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多