|
-
Jan 2nd, 2004, 09:13 AM
#1
Thread Starter
Junior Member
Run other commands or applications..
Hi there..
I've a question on Java; how can I run a command from the Java code, for example, I want when click on a JButton to send command to the system such as "dir" or "copy" or run applications by something like "start winword"..
plz help me it's so important for me..
I've another question: is there a component I can use to show an HTML page inside it on a frame, how it's used. I use JBuilder 5.
Thanx2all.
-
Jan 2nd, 2004, 12:43 PM
#2
Dazed Member
As for your first question as far as i remember to run an application System.exec() was used but im not too sure though.
To display an html page you can use a javax.swing.JEditorPane which is able to handle frames, forms, hyperlinks, and parts of css Level 1. When you create your JEditorPane you can either pass in the actual html in the constructor with the mime type or you can just set the initial page with a Url passsed in as an arguement.
As i said before, JEditorPane is a able to handle hyperlinks. This is achieved with the use of HyperlinkListener interface or more specifically javax.swing.event.HyperlinkListener which contains this one method that you must implement. public void hyperlinkUpdate(HyperlinkEvent e)
-
Jan 3rd, 2004, 12:38 PM
#3
Thread Starter
Junior Member
I'll see..
thanx 4 ur reply, I'll check that then tell u.
thanx again.
-
Jan 7th, 2004, 05:28 AM
#4
I should add some things.
For the copy and dir commands, you'd best do that in code via the java.io.File class.
Executing applications is done with System.exec (or maybe it was Runtime.getRuntime().exec).
However, you cannot "execute" data files, like word documents. I wrote a small JNI class to do that, but I still need Linux and MacOS implementations.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2004, 12:01 PM
#5
Thread Starter
Junior Member
thanx CornBee 4 ur reply, but I'm beginner in Java may u please write an example of how these commands are to be written.
-
Jan 7th, 2004, 12:40 PM
#6
Ok, there's no copy command. Strange...
To list the files of a directory, use File.list or File.listFiles.
Code:
import java.io.File;
public class Dir {
public static void main(String[] args) {
File cwd = new File(".").getAbsolutePath();
System.out.println("Index of " + cwd);
System.out.println();
String[] files = cwd.list();
for(int i = 0; i < files.length; ++i) {
System.out.println(files[i]);
}
}
}
Usage:
java Dir
You can execute any executable using Runtime.exec().
Code:
public class Start {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.out.println("You must specify a file.");
return;
}
Runtime.getRuntime().exec(args[0]);
}
}
Usage:
java Start <executable name>
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2004, 06:12 AM
#7
Thread Starter
Junior Member
thanx again I'll try this and tell you..
-
Jan 13th, 2004, 07:17 AM
#8
Thread Starter
Junior Member
-
Feb 5th, 2004, 01:00 PM
#9
New Member
umm.. is it possible to code where java is able to click and parse information(such as password and username) to the third party program that was run...
example:
java runs my msn messenger and press the sign in button
it then fills the username and password and press Ok button for me...
I hope something like this is possible. If it is, pls guide me. Thank you.
-
Feb 5th, 2004, 06:39 PM
#10
You can look at the java.awt.Robot class, but it's some unpleasant stuff to do.
Which is why good applications should always provide a command line interface.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|