问:本程序能从文件中读出文字,但是不能按原文显示,比如文件中是一段很长的文字,且有换行。可是程序运行显示的只有其中的一部分,且没有分段。问:如何能按原文显示,能不能利用字节流来处理输入输出?还有就是程序中有部分代码,我不是很明白,希望得到解答,谢谢了!!!令:还有一个问题,在图形用户界面中如何控制JTextFeild和JTestArea中字符的大小?import java.awt.*;
import java.applet.*;
import java.io.*;
public class C12_2 extends Applet implements Runnable
{
int c;
char[] buffer = new char[255];
Thread th1=null;
String Message;
Font f = new Font("TimesRoman",Font.BOLD,24);
int x,y;
public void init()
{x = getSize().width/4;
y = getSize().height;}
public void start()
{ if(th1==null)
{th1=new Thread(this);
th1.start();
}}
public void run()
{ while(true)
{
y=y-5;
if(y==0){y=getSize().height;}
repaint();
try
{th1.sleep(500);}
catch(InterruptedException e){ }} }
public void paint(Graphics g){
FileReader in = null;
g.setFont(f);
try{
in = new FileReader("梦里花落知多少.txt");
while((c=in.read(buffer))!=-1){
int count = in.read(buffer);//这句话什么意思?buffer 的作用?
Message = new String(buffer,80,count-1);//这是什么方法,参数的意义?
g.drawString(Message,x,y);
}}
catch (IOException e) {}
finally { try {if (in!=null) in.close();}catch(IOException e){} }
}}
import java.applet.*;
import java.io.*;
public class C12_2 extends Applet implements Runnable
{
int c;
char[] buffer = new char[255];
Thread th1=null;
String Message;
Font f = new Font("TimesRoman",Font.BOLD,24);
int x,y;
public void init()
{x = getSize().width/4;
y = getSize().height;}
public void start()
{ if(th1==null)
{th1=new Thread(this);
th1.start();
}}
public void run()
{ while(true)
{
y=y-5;
if(y==0){y=getSize().height;}
repaint();
try
{th1.sleep(500);}
catch(InterruptedException e){ }} }
public void paint(Graphics g){
FileReader in = null;
g.setFont(f);
try{
in = new FileReader("梦里花落知多少.txt");
while((c=in.read(buffer))!=-1){
int count = in.read(buffer);//这句话什么意思?buffer 的作用?
Message = new String(buffer,80,count-1);//这是什么方法,参数的意义?
g.drawString(Message,x,y);
}}
catch (IOException e) {}
finally { try {if (in!=null) in.close();}catch(IOException e){} }
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货