944,188 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 547
  • Java RSS
Oct 12th, 2009
0

executing a .java file from another .java file

Expand Post »
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
java Syntax (Toggle Plain Text)
  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?
java Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
scias23 is offline Offline
69 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Socket passing double type value from c++ to java
Next Thread in Java Forum Timeline: Logical Error - Calculator - Memory





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC