• 0

GUI programming


Question

Hi, I am having trouble finding the right way to open a file through GUI and actionListener without going through JFileChooser. For example, I have a simple GUI that has a help menu, and I want it so that when I click on the Help menu item, it will open a certain file, such as HTML or txt. How can I go about implementing this in my program which implements actionListener ()?

I have attached my MenuListener, change the extension to .java to view it

thanks in advance :blush: :blush:

MenuListener.txt

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I dunno if this is what u want, but:

package allgemein;

import java.io.IOException;

public class OpenFiles {

	public static void main(String[] args) ?{
 ?try {
 ?	Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + filepath());
 ?	} catch (IOException e) {
// ? ?TODO Auto-generated catch block
 ?	e.printStackTrace();
 ?	}
 ?	}
 ? ?

	private static String filepath() {
 ?String filepath1 = "C:\\test.txt";
 ?return filepath1;
	}
}

that opens the file specified in the filepath1 string with its default application. u probably need to mod the code a little...

good luck

Edited by eccofresh
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.