I-Dont-Know

ToolbarWindow,java

Aug 18th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1. package execute;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.io.IOException;
  6.  
  7. import javax.swing.*;
  8.  
  9. @SuppressWarnings("serial")
  10. public class ToolbarWindow extends JFrame implements ActionListener{
  11.     String[] txt = {"C:/Program Files (x86)/OpenOffice 4/program/swriter.exe", "Word"};
  12.     String[] sprdsht = {"C:/Program Files (x86)/OpenOffice 4/program/scalc.exe", "Excel"};
  13.     String[] sld = {"C:/Program Files (x86)/OpenOffice 4/program/simpress.exe", "PowerPoint"};
  14.     String[] img = {"C:/Program Files (x86)/OpenOffice 4/program/sdraw.exe", "Paint"};
  15.     String[] db = {"C:/Program Files (x86)/OpenOffice 4/program/sbase.exe", "Access"};
  16.     String[] math = {"C:/Program Files (x86)/OpenOffice 4/program/smath.exe", "Calculator"};
  17.     String[] web = {"C:/Program Files (x86)/OpenOffice 4/program/sweb.exe", "HTML Editor(OpenOfice)"};
  18.     String[] np = {"C:/Program Files (x86)/Notepad++/notepad++.exe", "Notepad++"};
  19.    
  20.     ToolbarWindow(){
  21.         JButton text = new JButton(txt[1]);
  22.         JButton spread = new JButton(sprdsht[1]);
  23.         JButton slide = new JButton(sld[1]);
  24.         JButton image = new JButton(img[1]);
  25.         JButton data = new JButton(db[1]);
  26.         JButton calc = new JButton(math[1]);
  27.         JButton html = new JButton(web[1]);
  28.         JButton notepad = new JButton(np[1]);
  29.        
  30.         text.addActionListener(this);
  31.         spread.addActionListener(this);
  32.         slide.addActionListener(this);
  33.         image.addActionListener(this);
  34.         data.addActionListener(this);
  35.         calc.addActionListener(this);
  36.         html.addActionListener(this);
  37.         notepad.addActionListener(this);
  38.         text.setActionCommand("text");
  39.         spread.setActionCommand("spread");
  40.         slide.setActionCommand("slide");
  41.         image.setActionCommand("image");
  42.         data.setActionCommand("data");
  43.         calc.setActionCommand("calc");
  44.         html.setActionCommand("html");
  45.         notepad.setActionCommand("notepad");
  46.        
  47.         add(text);
  48.         add(spread);
  49.         add(slide);
  50.         add(image);
  51.         add(data);
  52.         add(calc);
  53.         add(html);
  54.         add(notepad);
  55.        
  56.     }
  57.  
  58.     @Override
  59.     public void actionPerformed(ActionEvent e) {
  60.         // TODO Auto-generated method stub
  61.         if ( e.getActionCommand() == "text" ) {
  62.             try {
  63.                 Runtime.getRuntime().exec(txt[0]);
  64.             } catch (IOException e1) {
  65.                 // TODO Auto-generated catch block
  66.                 e1.printStackTrace();
  67.             }
  68.         }
  69.         if ( e.getActionCommand() == "spread" ) {
  70.             try {
  71.                 Runtime.getRuntime().exec(sprdsht[0]);
  72.             } catch (IOException e1) {
  73.                 // TODO Auto-generated catch block
  74.                 e1.printStackTrace();
  75.             }
  76.         }
  77.         if ( e.getActionCommand() == "slide" ) {
  78.             try {
  79.                 Runtime.getRuntime().exec(sld[0]);
  80.             } catch (IOException e1) {
  81.                 // TODO Auto-generated catch block
  82.                 e1.printStackTrace();
  83.             }
  84.         }
  85.         if ( e.getActionCommand() == "image" ) {
  86.             try {
  87.                 Runtime.getRuntime().exec(img[0]);
  88.             } catch (IOException e1) {
  89.                 // TODO Auto-generated catch block
  90.                 e1.printStackTrace();
  91.             }
  92.         }
  93.         if ( e.getActionCommand() == "data" ) {
  94.             try {
  95.                 Runtime.getRuntime().exec(db[0]);
  96.             } catch (IOException e1) {
  97.                 // TODO Auto-generated catch block
  98.                 e1.printStackTrace();
  99.             }
  100.         }
  101.         if ( e.getActionCommand() == "calc" ) {
  102.             try {
  103.                 Runtime.getRuntime().exec(math[0]);
  104.             } catch (IOException e1) {
  105.                 // TODO Auto-generated catch block
  106.                 e1.printStackTrace();
  107.             }
  108.         }
  109.         if ( e.getActionCommand() == "html" ) {
  110.             try {
  111.                 Runtime.getRuntime().exec(web[0]);
  112.             } catch (IOException e1) {
  113.                 // TODO Auto-generated catch block
  114.                 e1.printStackTrace();
  115.             }
  116.         }
  117.         if ( e.getActionCommand() == "notepad" ) {
  118.             try {
  119.                 Runtime.getRuntime().exec(np[0]);
  120.             } catch (IOException e1) {
  121.                 // TODO Auto-generated catch block
  122.                 e1.printStackTrace();
  123.             }
  124.         }
  125.     }
  126.     private static void createAndShowGUI() {
  127.  
  128.         //Create and set up the window.
  129.         JFrame frame = new JFrame();
  130.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  131.  
  132.         //Create and set up the content pane.
  133.         ToolbarWindow newContentPane = new ToolbarWindow(); //content panes must be opaque
  134.         frame.setContentPane(newContentPane);
  135.         frame.setSize(1366, 50);
  136.         //Display the window.
  137.         frame.pack();
  138.         frame.setVisible(true);
  139.     }
  140.  
  141.     public static void main(String[] args) {
  142.         //Schedule a job for the event-dispatching thread:
  143.         //creating and showing this application's GUI.
  144.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  145.             public void run() {
  146.                 createAndShowGUI();
  147.             }
  148.         });
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment