做项目的网站,基于php的网站开发,网络营销推广策略有哪些,服务器上面建设网站小编典典根据应用程序或小程序是使用AWT还是Swing#xff0c;答案会略有不同。(基本上#xff0c;以J诸如JApplet和JFrame为开头的类是Swing和Appletand Frame是AWT。)无论哪种情况#xff0c;基本步骤都是#xff1a;将图像绘制或加载到Image对象中。在要绘制背景的绘画事…小编典典根据应用程序或小程序是使用AWT还是Swing答案会略有不同。(基本上以J诸如JApplet和JFrame为开头的类是Swing和Appletand Frame是AWT。)无论哪种情况基本步骤都是将图像绘制或加载到Image对象中。在要绘制背景的绘画事件中绘制背景图像Component。步骤1.可以通过使用Toolkit类或通过ImageIO类来加载图像。该Toolkit.createImage方法可用于Image从中指定的位置加载StringImage img Toolkit.getDefaultToolkit().createImage(background.jpg);同样ImageIO可以使用Image img ImageIO.read(new File(background.jpg);第2步。Component应该获取背景的绘画方法将被覆盖并将其绘画Image到组件上。对于AWT要覆盖的paint方法是方法并使用传递给该方法drawImage的Graphics对象的paint方法public void paint(Graphics g){// Draw the previously loaded image to Component.g.drawImage(img, 0, 0, null);// Draw sprites, and other things.// ....}对于Swing要覆盖的paintComponent方法是的方法JComponent并Image使用在AWT中所做的绘制。public void paintComponent(Graphics g){// Draw the previously loaded image to Component.g.drawImage(img, 0, 0, null);// Draw sprites, and other things.// ....}简单组件示例这是一个Panel在实例化时加载图像文件并在其自身上绘制图像的class BackgroundPanel extends Panel{// The Image to store the background image in.Image img;public BackgroundPanel(){// Loads the background image and stores in img object.img Toolkit.getDefaultToolkit().createImage(background.jpg);}public void paint(Graphics g){// Draws the img to the BackgroundPanel.g.drawImage(img, 0, 0, null);}}有关绘画的更多信息2020-09-16