What type of program? A jar? A classfile?
The easy way would be to add the jar to your classpath, then just call its main class.
If it's just a class file, drag it to your working directory, and call it that way.
so lets say your program is called Mario.java, and the program you want to run is "Davey.jar" which is in the same folder...
Compile:
c:\> javac -cp .;Davey.jar Mario.java
Run:
c:\> java -cp .;Davey.jar Mario
Code:
import com.code.Davey; // You need to know what the main class is called
public class Mario() {
// Run Davey.jar
Davey j = new Davey();
j.setVisible(true);
}
In the event you want to do it dynamically, its gets tricky, but its possible, just ask.
-FBL
hi!
i asked you which version of jdk you are using. if you are using JDK1.6 then there is a class called java.awt.Desktop
explore that class. if you are not using JDK1.6 then you have write a class like this class. for windows you have run a pps/word file using rundll and as a process camickr described. and you have to check how to run in other OS (like Linux, MAC).
regards
Aniruddha
I've got JDK1.6 and I searched more about java.awt.Desktop
but I still don't know how to do it....
public void actionPerformed ( ActionEvent e){
String command = e. getActionCommand ();
if ( command.equals("Open"))
//what command shall I write here so that I can open a program?
well it doesn't work.I've wrote
Desktop.getDesktop().open(File Java1.class); and it gives me this errors
Program.java:57: ')' expected
Desktop.getDesktop().open(File Java1.class);
^
Program.java:57: not a statement
Desktop.getDesktop().open(File Java1.class);
^
Program.java:57: ';' expected
Desktop.getDesktop().open(File Java1.class);
^
[nobr]can you please post your code here....
import java.awt.Desktop;
import java.io.File;
/**
* @author: Aniruddha<br>
* @date: May 14, 2007, 9:49:53 AM<br>
* @source: OpenFile.java<br>
* @project: HelpForum<br>
*/
public class OpenFile
{
/**
* @author: Aniruddha<br>
* @date: May 14, 2007, 9:49:53 AM<br>
* @param args
*/
public static void main(String[] args)
{
try
{
Desktop.getDesktop().open(new File("c:\\test.txt"));
}
catch(Throwable a_th)
{
}
}
}
in my machine this is working fine. provided you have test.txt file in your c drive
regards
Aniruddha[/nobr]
import java.awt.*;
import java.awt.event.*;
import java.awt.Desktop;
import java.io.File;
public class Program extends Frame implements ActionListener{
public Program (String titlu){
super(titlu);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(400,400);
setBackground(Color.lightGray);
Label acces=new Label("Introduceti numele si parola!");
acces.setText("");
add(acces);
Panel adaugare=new Panel();
Button adauga=new Button("Adauga un element");
adaugare.add(adauga);//adaugam panel pe suprafata ferestrei
adauga.setForeground(Color.red);//stabilim culoarea pentru panel
add(adaugare,BorderLayout.NORTH);//adaugam panel pe suprafata ferestrei
Button b1=new Button("Java1");
add(b1,BorderLayout.WEST);
Button b2=new Button("Java2");
add(b2,BorderLayout.EAST);
Button b3=new Button("Exit");
add(b3,BorderLayout.SOUTH);
MenuBar mb=new MenuBar();
Menu fisier=new Menu("File");
fisier.add(new MenuItem("Exit"));
mb.add(fisier);
setMenuBar(mb);
fisier.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
adauga.addActionListener(this);
}
public void actionPerformed ( ActionEvent e){
String command = e. getActionCommand ();
if ( command.equals("Java1"))//the errorDesktop.getDesktop().open(new File("c:\\test.txt"));
}
// Valabila si pentru meniu si pentru buton
public static void main(String args[]){
//throws IOException{
//Runtime rt = Runtime.getRuntime();
Program f=new Program("Atestat");
f.show();f.setResizable(false);
}
}