eclipse 中写form程序 写一个form程序,在一个form上 放一个按钮, 点击这个按钮后,打开一个文本文件,显示到form上.有人给我出了这个题目。求思路啊,我现在连用什么写都还不知道呢 百度 gooogle 出来的信息好少。麻烦了各位大大 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是GUI程序吧public class LoadTxt extends JFrame { private static final String FILE_NAME = "C:\\Hello.java"; // 文件名,可修改 JButton btnLoad; JTextArea txtArea; public LoadTxt() { this.setTitle("Text File Loader"); // 按钮,放在JFrame下方(南部区域) btnLoad = new JButton("Click Here to Load File"); btnLoad.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); loadFile(FILE_NAME); } }); this.add(btnLoad, BorderLayout.SOUTH); // 文本区,放在JFrame中部区域 txtArea = new JTextArea(); this.add(txtArea, BorderLayout.CENTER); } private void loadFile(String filename) { Scanner sc = null; try { sc = new Scanner(new File(filename)); txtArea.setText(""); // 清空 while (sc.hasNextLine()) { txtArea.append(sc.nextLine()); txtArea.append("\n"); } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (sc != null) sc.close(); } } public static void main(String[] args) { LoadTxt wnd = new LoadTxt(); wnd.setSize(600, 500); wnd.setVisible(true); }} 示例参见 %JAVA_HOME%\demo\jfc\Notepad\Notepad.jar代码参见 %JAVA_HOME%\demo\jfc\Notepad\src 请诸位高手点拨:现在的ISP运营商,面向自己的ICP,分成的行价是多少?谢谢高手!! load十万条记录到内存,怎样尽量避免内存泄露?有经验的来.. 纠结了.....如何返回最后一个结果集 怎么取到文本输入域的值 Hibernate 读写Blob和Clob的问题! hibernate和struts的老问题,未解决! 二级联动菜单实在搞不出来了,大家帮帮忙啊 如何读取打包在jar中的bean.xml 关于用SAX解析XML的问题! session保存在哪里啊 Spring3.1 MVC +Ehcache问题 dedecms
public class LoadTxt extends JFrame { private static final String FILE_NAME = "C:\\Hello.java"; // 文件名,可修改
JButton btnLoad;
JTextArea txtArea; public LoadTxt() {
this.setTitle("Text File Loader"); // 按钮,放在JFrame下方(南部区域)
btnLoad = new JButton("Click Here to Load File");
btnLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
loadFile(FILE_NAME);
}
});
this.add(btnLoad, BorderLayout.SOUTH); // 文本区,放在JFrame中部区域
txtArea = new JTextArea();
this.add(txtArea, BorderLayout.CENTER);
} private void loadFile(String filename) {
Scanner sc = null;
try {
sc = new Scanner(new File(filename));
txtArea.setText(""); // 清空
while (sc.hasNextLine()) {
txtArea.append(sc.nextLine());
txtArea.append("\n");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (sc != null)
sc.close();
}
} public static void main(String[] args) {
LoadTxt wnd = new LoadTxt();
wnd.setSize(600, 500);
wnd.setVisible(true);
}}
代码参见 %JAVA_HOME%\demo\jfc\Notepad\src