为什么要继承Frame类呢
import java.io.*;
public class FileDialog1 extends Frame{ // x1 继承Frame类
FileDialog fopen; //文件对话框/
TextArea ta;//显示文件内容的TextArea
public FileDialog1(String title){ //构造函数
super(title); //调用父类构造函数,设定窗口标题
ta=new TextArea(); //TextArea对象
add(ta); //象对象添加ta
setSize(300,300); //设定大小
}
//显示文件对话框,并获取选中文件的名称
public String showLoad(){
fopen=new FileDialog(this,"打开文件",FileDialog.LOAD); //打开模式
fopen.setVisible(true); //显示文件对话框,this处于等待状态
//关闭文件对话框,才继续执行
String fileName=fopen.getFile(); //fileName保存选中文件的名称
String fileDir=fopen.getDirectory(); //fileDir保存选中文件的目录
if(fileName==null){ // 若选中文件的名称为null,则返回null值
return null;
}
return fileDir+"//"+fileName; //获取文件的绝对目录
}
//读取文件内容,并显示在ta中
public void loadFile(String fileName) throws IOException{
BufferedReader br=new BufferedReader(new FileReader(fileName));
String aline ;
while((aline=br.readLine())!=null)
ta.append(aline+'\n');
br.close();
}
public void showSave(){} //省略
public void saveFile(){} //省略
public static void main(String[] args){
FileDialog1 fdlg=new FileDialog1("文件");
String fileName; //文件名
//若文件名不存在,则输入相应的提示信息
if((fileName=fdlg.showLoad())==null)
System.out.println("尚未选取文件");
else{
//读取文件。处理loadFile()方法可能抛出的异常
try{
fdlg.loadFile(fileName);
}catch(IOException ie){
System.out.println(ie);
}
}
fdlg.setVisible(true); //显示窗口
}
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x1为什么要继承Frame
相关推荐
自定义UIAlertView
自定义UIAlertView,直接继承UIView,支持背景和按钮的自定义
SmartGWT 2.0 API.zip
smartGWT 2.0 API,英文版,适合初学者熟悉使用
ios-自定义tabBar.zip
自定义tabBar,完全移除系统的tabBar,创建button继承于UIView
iOS开发高级程序员面试题-答案.pdf,这是一份不错的文件
iOS开发高级程序员面试题-答案.pdf,这是一份不错的文件
matlab特殊符号代码-frame:一个继承自data.frame的类,默认为'drop=FALSE',一个'end'关键字,'all'的0
matlab特殊符号代码'frame' 一个从 data.frame 继承的 S4 类 找我 一个继承自 data.frame 的类,默认为drop=FALSE ,一个 'end' 关键字,'all' 的 0 索引和一个 'desc' 字段。 问题 尽管非常强大,但 R 语言主要用于交互式使用。 因此,在x[i,j] ,为i或j设置这样的值来模拟x[,j]或x[i,]并不是直接的。 使用TRUE (将被回收)是获得它的一个技巧。 T = TRUE x = matrix ( 1 : 12 , ncol = 3 ) identical( x [, 3 ], x [ T , 3 ]) ## [1] TRUE identical( x [, 3 ], `[`( x , T , 3 )) ## [1] TRUE z = y = x x [, 3 ] = 0 y [ T , 3 ] = 0 identical( x , y ) ## [1] TRUE z = `[<-`( z , T , 3 , 0 ) identical( x , z ) ## [1] TRUE 这也适用于 data.frame


Java SE
