在JAVA中的AWT中怎么将图片加到窗体和容积上面去 一个初学者的问题:在JAVA中的AWT中怎么将图片加到窗体和容积上面去? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 override paintComponent(Graphic g)方法 import java.awt.*;import javax.swing.*;import javax.imageio.*;import java.io.*;public class PaintComponent extends JButton{ public void paintComponent(Graphics g){ super.paintComponent(g); try{ Image image = ImageIO.read(new File(".\\rsc\\1.gif")); g.drawImage(image, 0,0,image.getWidth(null),image.getHeight(null),null); }catch(IOException e){ e.printStackTrace(); } } public static void main(String args[]){ JFrame frame = new JFrame(); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new PaintComponent(),BorderLayout.CENTER); frame.setSize(new Dimension(400,300)); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }} java爬虫项目,如何获取js执行后的完整网页源代码? java数组的问题(二维)。 帮忙编写一个小JAVA程序,我是初学者,不太会! (在线等)关于判断Scanner输入的问题 求助:java自动拼写检查 运行程序时,错误的提示. (虽然没有分数给各位大侠,但是还是希望能来帮我解决下疑问) 先谢谢了。 与数据库连接问题 大家给推荐一下java的书. 谁能提供一个好点的SQL Server 7的JDBC驱动?谢谢啦~! 有关传值的问题 Date() 类中的问题?跪地求解!! 请问synchronized这样用对吗?困惑中!!!!
import javax.swing.*;
import javax.imageio.*;
import java.io.*;public class PaintComponent extends JButton{
public void paintComponent(Graphics g){
super.paintComponent(g);
try{
Image image = ImageIO.read(new File(".\\rsc\\1.gif"));
g.drawImage(image,
0,0,image.getWidth(null),image.getHeight(null),null);
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String args[]){
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new PaintComponent(),BorderLayout.CENTER);
frame.setSize(new Dimension(400,300));
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}