executing a .java file from another .java file

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 43
Reputation: scias23 is an unknown quantity at this point 
Solved Threads: 0
scias23's Avatar
scias23 scias23 is offline Offline
Light Poster

executing a .java file from another .java file

 
0
  #1
Oct 12th, 2009
WHAT i want to happen is, when i click the CALCULATOR menu item, my separate Calculator.java will run on the MenuShortCut JFrame.

AGAIN, i want the separate .java file to appear on THE SAME JFrame of MenuShortCut class.

here's what i've got
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3.  
  4. public class MenuShortcut extends JFrame implements ActionListener{
  5. JMenuBar menuBar;
  6. JMenu files,help;
  7. JMenuItem cs[],calc,game,exit,about;
  8.  
  9. public MenuShortcut() {
  10. super("Team Shrek");
  11. menuBar = new JMenuBar();
  12. files = new JMenu("File");
  13. help = new JMenu("Help");
  14. cs = new JMenuItem[5];
  15. calc = new JMenuItem("Calculator");
  16. game = new JMenuItem("Word Game");
  17. exit = new JMenuItem("Exit");
  18. about = new JMenuItem("About");
  19.  
  20. for(int i=0;i<5;i++) {
  21. cs[i] = new JMenuItem("CaseStudy "+(i+1));
  22. cs[i].addActionListener(this);
  23. files.add(cs[i]);
  24. }
  25. files.addSeparator();
  26. files.add(calc);
  27. files.add(game);
  28. files.addSeparator();
  29. files.add(exit);
  30.  
  31. help.add(about);
  32.  
  33. menuBar.add(files);
  34. menuBar.add(help);
  35.  
  36. setJMenuBar(menuBar);
  37.  
  38. setSize(250,200);
  39. setVisible(true);
  40. setDefaultCloseOperation(EXIT_ON_CLOSE);
  41. }
  42.  
  43. public static void main(String[] args) {
  44. new MenuShortcut();
  45. }
  46.  
  47. public void actionPerformed(ActionEvent e) {
  48. //some events here
  49. }
  50. }

can i do that using this?
  1. Runtime.getRuntime().exec( "java programname.java" );

if yes, codes do i need to add in order to get it working? (i get unreported exception error)

thanks.
a joke.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC