最新下载
热门教程
- 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(); } } | |
相关文章
- 凡人修仙传人界篇 体修功法推荐攻略 07-27
- 凡人修仙传人界篇预约礼包码 07-27
- 《凡人修仙传人界篇》开荒新手攻略 07-27
- 提升企业决策效率的四个策略:AI大数据怎样优化市场营销 07-27
- 提高AI数据模型应用效果的七种策略与客户体验 07-27
- cdr可以打开ai格式的文件吗?5种解决方案分析与兼容性探索 07-27