日期:2014-05-20 浏览次数:20735 次
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class ResourceTest {
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run() {
ResourceFrame frame = new ResourceFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class ResourceFrame extends JFrame{
public ResourceFrame(){
setSize(500, 300);
URL url = getClass().getResource("speed.gif");
Image img = Toolkit.getDefaultToolkit().getImage(url);
setIconImage(img);
JTextArea area = new JTextArea();
InputStream stream = getClass().getResourceAsStream("student.txt");
Scanner in = new Scanner(stream);
while(in.hasNext())
area.append(in.nextLine()+"\n");
add(area);
}
}