javaswt打开文件|怎样读文件内容到文本域中(java SWT)

『壹』 java中,用SWT,我想在一个窗体中点击一个菜单,然后在这个窗体内打开另外一个已经建好了的窗体。请问怎么

第一个窗体(被调用的那个) class frame extends JFrame{ //无参构造 public frame(){ this.setsize(500,400); this.setVisible(true); }} 第二个窗体 class frame2 extends JFrame implements ActionListener{ public static void main(String[] aegs){ new frame2(); } public frame2(){ new frame2(); JMenuBar m= new JMenuBar(); JMenu caidan=new JMenu("文件"); m.add(caidan); JMenuItem xinjian=new JMenuItem("新建"); caidan.add(xinjian); xinjian.addActionListener(this); this.setSize(500,400); this.setJMenuBar(m); this.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0) { new frame(); }}代码可以直接使用

『贰』 怎样读文件内容到文本域中(java SWT)

//写了段简单的代码提供你参考import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import javax.swing.JFrame;import javax.swing.JTextArea;public class Test extends JFrame{public static void main(String[] args) {Test test = new Test();test.setSize(300, 400);test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JTextArea jta = new JTextArea();try {jta.setText(test.getFile("D:\\a.txt"));//这只文本域的只} catch (IOException e) {e.printStackTrace();}test.add(jta);test.setVisible(true);}/*** 读取文件的方法* @param filepath* @return* @throws IOException*/public String getFile(String filepath) throws IOException{File file = new File(filepath);FileInputStream fis = new FileInputStream(file);BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis));//转换成字符流,有readline方法可以直接读取一行的数据,方便文本的读取StringBuffer str = new StringBuffer("");//读取第一行String tempstr = bufferedReader.readLine();while (tempstr!=null) {str.append(tempstr);tempstr = bufferedReader.readLine();//读取下一行}bufferedReader.close();return str.toString();}}

『叁』 swt文件怎么打开

应该是swf文件吧,可以用Adobe Flash打开,也可以在IE是打开。Flash是美国的MACROMEDIA公司于1999年6月推出的优秀网页动画设计软件。它是一种交互式动画设计工具,用它可以将音乐,声效,动画以及富有新意的界面融合在一起,以制作出高品质的网页动态效果。

『肆』 java SWT 加载文件内容

楼主,你的代码好多错误。帮你改了部分,主要还是看“ //这里应该怎么写代码”下面的代码。java处理文件需要流的知识。我这里用的Scanner需要jdk1.5以上版本才能用。你先运行看看吧package com.swtjface;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Scanner;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;public class Test { public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(500, 375); final Button button = new Button(shell, SWT.PUSH); button.setBounds(0, 0, 150, 35); button.setText("打开文件"); final Text text = new Text(shell, SWT.BORDER|SWT.MULTI); text.setBounds(0, 40, 500, 375); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // 这里应该怎么写代码 FileDialog dlg = new FileDialog(shell, SWT.OPEN); dlg.setText("选择一个TXT文件"); dlg.setFilterExtensions(new String[] { "*.txt" }); dlg.setFilterNames(new String[] { "文本文件(*.txt)" }); String filePath = dlg.open(); System.out.println(filePath); try { Scanner in = new Scanner(new FileInputStream(new File( filePath))); while (in.hasNextLine()) { text.append(in.nextLine() + "\r\n"); } } catch (FileNotFoundException e1) { e1.printStackTrace(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }}

『伍』 java用swt选择文件和文件夹是哪个类

在弹出的快捷菜单中选择命令选择“Existing Projects into Workspace”选择“Select archive file”进入页面后 有一个小段的标题为Releases可以通过点击下面的相关超链接找到相关文件 进行下载放到 eclipse下的plugins文件夹下(整个文件夹都放进去哦)然后 自己建个工程在Eclipse IDE的Package Explorer视图中单击右键.eclipse.swt项目,把刚才那个留着的工程引入到这个工程里.swt”,直接ok就好了然后然你选择安装项目.eclipse,选定该项目并单击“Finish”按钮。这个工程就这么留着哦~~~Second——下面安装 swt Designer然后。打开项目的构建路径配置窗口。在新建工程中选择 other然后然你选择工程选择swt就这个就可以了,怕麻烦的话就 select all~然后finish就进行在线安装了,点击 Add选项 在弹出对话框中输入网址由于我已经装过了,在该对话框中选择“Projects”选项卡在该页面中,重启后,通过将Eclipse SWT项目加入到项目的“依赖项目”列表中,单击“Add”按钮,在弹出的项目列表中选择“org,打开eclipse在help菜单里有选择 install new software进入install new software 后,单击“OK”按钮完成构建路径配置,选择dialog啥的都可以工程建完后。注意org.eclipse.swt中包含SWT的源代码压缩文件,此时该对话框的项目列表中会显示一个org,所以显示Duplicate location 如果没装过,就可以使用了(好像不用引用也成),在安装过程中可能会出现 unsign 的警告,继续安装即可,安装之后会提示重启eclipse,就可以使用了。之后再那个SWT/JFace那个工程里在建个项目就好了!,单击“Browse”按钮,可以方便地查看这些源代码以及相应的Java Doc文件,定位到之前下载的SWT工具包


赞 (0)