[求助]关于输出文件内容在图形界面上的
import java.awt.*;import javax.swing.*;
import java.io.*;
import java.net.*;
public class PanelFrame extends JFrame{
public PanelFrame (int width,int height){
setSize(width,height);
setTitle("预约结果");
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int x=(screenSize.width-width)/2;
int y=(screenSize.height-height)/2;
setLocation(x,y);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
public static void main(String args[]){
PanelFrame frame=new PanelFrame(300,200);
ContentPanel bl=new ContentPanel();
frame.setContentPane(bl);
frame.setVisible(true);
}
}
class ContentPanel extends JPanel {
public void paintComponent(Graphics g)throws Exception{
super.paintComponent(g);
FileReader fr=new FileReader("F:\\新建文件夹\\老一.txt");
BufferedReader br=new BufferedReader(fr);
String s;
while((s=br.readLine())!=null){
try{
g.drawString(s,0,0);
}catch(IOException e){
g.drawString("学生信息加载失败",100,100);
}
}
fr.close();
}
}
修改一下。。。。。。
[此贴子已经被作者于2007-11-9 23:26:23编辑过]