Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to execute another application out side of java. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Execute another application 31-Jul-04
Category
System
Language
JBuilder 8.X
Views
490
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Darley, F. Joe
Reference URL:
			1   
2   package samplecode;
3   
4   import java.awt.*;
5   import java.awt.event.*;
6   import javax.swing.*;
7   
8   /**
9    * <p>Title: Execute Sample</p>
10   * <p>Description: Thip program shows how to execute a program outside of
11   *  java </p>
12   * <p>Company: Developer's super Page.com</p>
13   */
14  
15  
16  public class SampleFrame extends JFrame {
17    JPanel contentPane;
18    BorderLayout borderLayout1 = new BorderLayout();
19    JPanel jpnlMain = new JPanel();
20    GridBagLayout gridBagLayout1 = new GridBagLayout();
21    JButton btnExecute = new JButton();
22  
23    //Construct the frame
24    public SampleFrame() {
25      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
26      try {
27        jbInit();
28      }
29      catch(Exception e) {
30        e.printStackTrace();
31      }
32    }
33  
34    //Component initialization
35    private void jbInit() throws Exception  {
36      contentPane = (JPanel) this.getContentPane();
37      contentPane.setLayout(borderLayout1);
38      this.setSize(new Dimension(400, 300));
39      this.setTitle("Execute Application");
40      jpnlMain.setLayout(gridBagLayout1);
41      contentPane.setMinimumSize(new Dimension(400, 300));
42      jpnlMain.setMinimumSize(new Dimension(400, 256));
43      jpnlMain.setPreferredSize(new Dimension(400, 256));
44      btnExecute.setText("Execute");
45      btnExecute.addActionListener(new SampleFrame_btnExecute_actionAdapter(this));
46      contentPane.add(jpnlMain,  BorderLayout.CENTER);
47      jpnlMain.add(btnExecute,    new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
48              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, -10, 
49  0, 10), 0, 0));
50    }
51  
52    //Overridden so we can exit when window is closed
53    protected void processWindowEvent(WindowEvent e) {
54      super.processWindowEvent(e);
55      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
56        System.exit(0);
57      }
58    }
59  
60    void btnExecute_actionPerformed(ActionEvent e) {
61      /* this function execute notepad and if not successfull it
62         will display an error message to the user */
63      
64          try
65           {
66         //Execute notpad
67          Runtime.getRuntime().exec("C:\\winnt\\Notepad.exe");
68            }
69            catch(Exception ioe)
70            {
71            //Display Error Message  
72            JOptionPane Pane = new JOptionPane();
73            Pane.showMessageDialog(null,  ioe.toString(),
74                           "Error",
75                           JOptionPane.ERROR_MESSAGE);
76         }
77  
78    }
79  }
80  
81  class SampleFrame_btnExecute_actionAdapter implements java.awt.event.ActionListener 
82  {
83    SampleFrame adaptee;
84  
85    SampleFrame_btnExecute_actionAdapter(SampleFrame adaptee) {
86      this.adaptee = adaptee;
87    }
88    public void actionPerformed(ActionEvent e) {
89      adaptee.btnExecute_actionPerformed(e);
90    }
91  }


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC