Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package execute;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class ToolbarWindow extends JFrame implements ActionListener{
- String[] txt = {"C:/Program Files (x86)/OpenOffice 4/program/swriter.exe", "Word"};
- String[] sprdsht = {"C:/Program Files (x86)/OpenOffice 4/program/scalc.exe", "Excel"};
- String[] sld = {"C:/Program Files (x86)/OpenOffice 4/program/simpress.exe", "PowerPoint"};
- String[] img = {"C:/Program Files (x86)/OpenOffice 4/program/sdraw.exe", "Paint"};
- String[] db = {"C:/Program Files (x86)/OpenOffice 4/program/sbase.exe", "Access"};
- String[] math = {"C:/Program Files (x86)/OpenOffice 4/program/smath.exe", "Calculator"};
- String[] web = {"C:/Program Files (x86)/OpenOffice 4/program/sweb.exe", "HTML Editor(OpenOfice)"};
- String[] np = {"C:/Program Files (x86)/Notepad++/notepad++.exe", "Notepad++"};
- ToolbarWindow(){
- JButton text = new JButton(txt[1]);
- JButton spread = new JButton(sprdsht[1]);
- JButton slide = new JButton(sld[1]);
- JButton image = new JButton(img[1]);
- JButton data = new JButton(db[1]);
- JButton calc = new JButton(math[1]);
- JButton html = new JButton(web[1]);
- JButton notepad = new JButton(np[1]);
- text.addActionListener(this);
- spread.addActionListener(this);
- slide.addActionListener(this);
- image.addActionListener(this);
- data.addActionListener(this);
- calc.addActionListener(this);
- html.addActionListener(this);
- notepad.addActionListener(this);
- text.setActionCommand("text");
- spread.setActionCommand("spread");
- slide.setActionCommand("slide");
- image.setActionCommand("image");
- data.setActionCommand("data");
- calc.setActionCommand("calc");
- html.setActionCommand("html");
- notepad.setActionCommand("notepad");
- add(text);
- add(spread);
- add(slide);
- add(image);
- add(data);
- add(calc);
- add(html);
- add(notepad);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if ( e.getActionCommand() == "text" ) {
- try {
- Runtime.getRuntime().exec(txt[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "spread" ) {
- try {
- Runtime.getRuntime().exec(sprdsht[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "slide" ) {
- try {
- Runtime.getRuntime().exec(sld[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "image" ) {
- try {
- Runtime.getRuntime().exec(img[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "data" ) {
- try {
- Runtime.getRuntime().exec(db[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "calc" ) {
- try {
- Runtime.getRuntime().exec(math[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "html" ) {
- try {
- Runtime.getRuntime().exec(web[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- if ( e.getActionCommand() == "notepad" ) {
- try {
- Runtime.getRuntime().exec(np[0]);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Create and set up the content pane.
- ToolbarWindow newContentPane = new ToolbarWindow(); //content panes must be opaque
- frame.setContentPane(newContentPane);
- frame.setSize(1366, 50);
- //Display the window.
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- //Schedule a job for the event-dispatching thread:
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment