最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
利用java制作一个小的目录查询器的方法
时间:2022-11-14 23:25:46 编辑:袖梨 来源:一聚教程网
实例如下:
代码如下 | 复制代码 |
importjava.util.*; importjavax.swing.*; importjava.awt.*; importjava.io.*; importjava.awt.event.*; classMyWindow{ privateFrame f1; privateButton bt1; privateTextField tx1; privateTextArea tx2; MyWindow(){ init(); } publicvoidinit(){ f1=newFrame("窗体"); f1.setBounds(300,100,600,500); f1.setLayout(newFlowLayout()); bt1=newButton("按钮"); tx1=newTextField(30); tx2=newTextArea(25,70); f1.add(tx1); f1.add(bt1); f1.add(tx2); event(); f1.setVisible(true);
}
privatevoidevent(){ bt1.addActionListener(newActionListener(){ publicvoidactionPerformed(ActionEvent e){
String dirpath=tx1.getText(); File dir =newFile(dirpath); if(dir.exists()&& dir.isDirectory()){ String names[] =dir.list(); for(String name:names){ tx2.setText(name+"rn"); } } // System.out.println(s); //tx2.append(s);
} }); f1.addWindowListener(newWindowAdapter(){ publicvoidwindowClosing(WindowEvent E){ System.exit(0); } }); } publicstaticvoidmain(String args[]){ newMyWindow(); } } |
相关文章
- 金铲铲之战2024最新兑换码汇总大全 05-12
- 《浩劫前夕》攻略 简评+配置+下载 05-12
- 《夜族崛起》正式版最佳建家位置推荐 05-12
- 《夜族崛起》吸血鬼猎人位置介绍 05-12
- 《夜族崛起》新版本内容介绍 05-12
- 《非生物因素》制作食物方法 05-12