Example usage for java.lang System exit

List of usage examples for java.lang System exit

Introduction

In this page you can find the example usage for java.lang System exit.

Prototype

public static void exit(int status) 

Source Link

Document

Terminates the currently running Java Virtual Machine.

Usage

From source file:GridBagWithWeight.java

public static void main(String[] args) {
    JFrame f = new JFrame("Demonstrates the use of weightx, weighty constraints");
    JPanel p = new JPanel();

    p.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    p.setLayout(new GridBagLayout());
    c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 2, 2);
    c.weighty = 1.0;//from w  w  w . j a  v  a  2s .co  m
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    p.add(new JButton("Java"), c);
    c.gridx = 1;
    p.add(new JButton("Source"), c);
    c.gridx = 0;
    c.gridy = 1;
    p.add(new JButton("and"), c);
    c.gridx = 1;
    p.add(new JButton("Support."), c);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    f.addWindowListener(wndCloser);

    f.getContentPane().add(p);
    f.setSize(600, 200);
    f.show();
}

From source file:com.jeffy.hdfs.HDFSWriteFile.java

/**
 * ??hdfs//from   w  ww  . j a v  a 2  s  .  co m
 * 
 * @param args
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Please input two parameter!");
        System.out.println("Parameter: localfile hdfsfile");
        System.exit(1);
    }

    String localPath = args[0];
    String hdfsPath = args[1];
    //??
    Configuration config = new Configuration();
    //??
    try (InputStream in = new BufferedInputStream(new FileInputStream(localPath))) {
        FileSystem fs = FileSystem.get(URI.create(hdfsPath), config);
        try (FSDataOutputStream out = fs.create(new Path(hdfsPath), new Progressable() {
            @Override
            public void progress() {
                System.out.println(".");
            }
        })) {
            //??OutputStream,Hadooporg.apache.commons.io.IOUtils
            IOUtils.copy(in, out);
            System.out.println("File copy finished.");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:AreaAdd.java

public static void main(String s[]) {
    JFrame f = new JFrame("Pear");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }/* w  w w.ja  v a  2  s .c o m*/
    });
    JApplet applet = new AreaAdd();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(150, 200));
    f.show();
}

From source file:net.kolola.msgparsercli.MsgParseCLI.java

public static void main(String[] args) {

    // Parse options

    OptionParser parser = new OptionParser("f:a:bi?*");
    OptionSet options = parser.parse(args);

    // Get the filename
    if (!options.has("f")) {
        System.err.print("Specify a msg file with the -f option");
        System.exit(0);
    }// ww w  . j  a v  a 2s  .  co  m

    File file = new File((String) options.valueOf("f"));

    MsgParser msgp = new MsgParser();
    Message msg = null;

    try {
        msg = msgp.parseMsg(file);
    } catch (UnsupportedOperationException | IOException e) {
        System.err.print("File does not exist or is not a valid msg file");
        //e.printStackTrace();
        System.exit(1);
    }

    // Show info (as JSON)
    if (options.has("i")) {
        Map<String, Object> data = new HashMap<String, Object>();

        String date;

        try {
            Date st = msg.getClientSubmitTime();
            date = st.toString();
        } catch (Exception g) {
            try {
                date = msg.getDate().toString();
            } catch (Exception e) {
                date = "[UNAVAILABLE]";
            }
        }

        data.put("date", date);
        data.put("subject", msg.getSubject());
        data.put("from", "\"" + msg.getFromName() + "\" <" + msg.getFromEmail() + ">");
        data.put("to", "\"" + msg.getToRecipient().toString());

        String cc = "";
        for (RecipientEntry r : msg.getCcRecipients()) {
            if (cc.length() > 0)
                cc.concat("; ");

            cc.concat(r.toString());
        }

        data.put("cc", cc);

        data.put("body_html", msg.getBodyHTML());
        data.put("body_rtf", msg.getBodyRTF());
        data.put("body_text", msg.getBodyText());

        // Attachments
        List<Map<String, String>> atts = new ArrayList<Map<String, String>>();
        for (Attachment a : msg.getAttachments()) {
            HashMap<String, String> info = new HashMap<String, String>();

            if (a instanceof FileAttachment) {
                FileAttachment fa = (FileAttachment) a;

                info.put("type", "file");
                info.put("filename", fa.getFilename());
                info.put("size", Long.toString(fa.getSize()));
            } else {
                info.put("type", "message");
            }

            atts.add(info);
        }

        data.put("attachments", atts);

        JSONObject json = new JSONObject(data);

        try {
            System.out.print(json.toString(4));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // OR return an attachment in BASE64
    else if (options.has("a")) {
        Integer anum = Integer.parseInt((String) options.valueOf("a"));

        Encoder b64 = Base64.getEncoder();

        List<Attachment> atts = msg.getAttachments();

        if (atts.size() <= anum) {
            System.out.print("Attachment " + anum.toString() + " does not exist");
        }

        Attachment att = atts.get(anum);

        if (att instanceof FileAttachment) {
            FileAttachment fatt = (FileAttachment) att;
            System.out.print(b64.encodeToString(fatt.getData()));
        } else {
            System.err.print("Attachment " + anum.toString() + " is a message - That's not implemented yet :(");
        }
    }
    // OR print the message body
    else if (options.has("b")) {
        System.out.print(msg.getConvertedBodyHTML());
    } else {
        System.err.print(
                "Specify either -i to return msg information or -a <num> to print an attachment as a BASE64 string");
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/* w w  w . j a v a  2s. c  om*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);

    PopupMenu popup = new PopupMenu();
    MenuItem miExit = new MenuItem("Exit");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    miExit.addActionListener(al);
    popup.add(miExit);

    TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2", popup);

    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println(e.getActionCommand());
        }
    };
    ti.setActionCommand("My Icon");
    ti.addActionListener(al);

    MouseListener ml = new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            System.out.println("Tray icon: Mouse clicked");
        }

        public void mouseEntered(MouseEvent e) {
            System.out.println("Tray icon: Mouse entered");
        }

        public void mouseExited(MouseEvent e) {
            System.out.println("Tray icon: Mouse exited");
        }

        public void mousePressed(MouseEvent e) {
            System.out.println("Tray icon: Mouse pressed");
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("Tray icon: Mouse released");
        }
    };
    ti.addMouseListener(ml);
    MouseMotionListener mml = new MouseMotionListener() {
        public void mouseDragged(MouseEvent e) {
            System.out.println("Tray icon: Mouse dragged");
        }

        public void mouseMoved(MouseEvent e) {
            System.out.println("Tray icon: Mouse moved");
        }
    };
    ti.addMouseMotionListener(mml);
    tray.add(ti);
}

From source file:SystemTrayDemo.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;/*  w  w w  .j a  va 2s. co m*/
    }

    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("trayIcon.jpg");

    PopupMenu menu = new PopupMenu();

    MenuItem messageItem = new MenuItem("Show Message");
    messageItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "www.java2s.com");
        }
    });
    menu.add(messageItem);

    MenuItem closeItem = new MenuItem("Close");
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(closeItem);
    TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
    icon.setImageAutoSize(true);

    tray.add(icon);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*ww w  .  j ava  2 s .  c  om*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);

    PopupMenu popup = new PopupMenu();
    MenuItem miExit = new MenuItem("Exit");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    miExit.addActionListener(al);
    popup.add(miExit);

    TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2");
    ti.setPopupMenu(popup);

    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println(e.getActionCommand());
        }
    };
    ti.setActionCommand("My Icon");
    ti.addActionListener(al);

    MouseListener ml = new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            System.out.println("Tray icon: Mouse clicked");
        }

        public void mouseEntered(MouseEvent e) {
            System.out.println("Tray icon: Mouse entered");
        }

        public void mouseExited(MouseEvent e) {
            System.out.println("Tray icon: Mouse exited");
        }

        public void mousePressed(MouseEvent e) {
            System.out.println("Tray icon: Mouse pressed");
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("Tray icon: Mouse released");
        }
    };
    ti.addMouseListener(ml);
    MouseMotionListener mml = new MouseMotionListener() {
        public void mouseDragged(MouseEvent e) {
            System.out.println("Tray icon: Mouse dragged");
        }

        public void mouseMoved(MouseEvent e) {
            System.out.println("Tray icon: Mouse moved");
        }
    };
    ti.addMouseMotionListener(mml);
    tray.add(ti);
}

From source file:DOMDump.java

static public void main(String[] arg) {
    boolean validate = true;

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(validate);/*from  www  . ja v  a2s  .  c om*/
    dbf.setNamespaceAware(true);
    dbf.setIgnoringElementContentWhitespace(true);

    // Parse the input to produce a parse tree with its root
    // in the form of a Document object
    Document doc = null;
    try {
        DocumentBuilder builder = dbf.newDocumentBuilder();
        builder.setErrorHandler(new MyErrorHandler());
        InputSource is = new InputSource("personWithDTD.xml");
        doc = builder.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (ParserConfigurationException e) {
        System.err.println(e);
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
    dump(doc);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*from  w w  w. ja va  2 s  .  co  m*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);

    PopupMenu popup = new PopupMenu();
    MenuItem miExit = new MenuItem("Exit");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    miExit.addActionListener(al);
    popup.add(miExit);

    TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2");
    ti.setPopupMenu(popup);

    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println(e.getActionCommand());
        }
    };
    ti.setActionCommand("My Icon");
    ti.addActionListener(al);

    MouseListener ml = new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            System.out.println("Tray icon: Mouse clicked");
        }

        public void mouseEntered(MouseEvent e) {
            System.out.println("Tray icon: Mouse entered");
        }

        public void mouseExited(MouseEvent e) {
            System.out.println("Tray icon: Mouse exited");
        }

        public void mousePressed(MouseEvent e) {
            System.out.println("Tray icon: Mouse pressed");
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("Tray icon: Mouse released");
        }
    };
    ti.addMouseListener(ml);
    MouseMotionListener mml = new MouseMotionListener() {
        public void mouseDragged(MouseEvent e) {
            System.out.println("Tray icon: Mouse dragged");
        }

        public void mouseMoved(MouseEvent e) {
            System.out.println("Tray icon: Mouse moved");
        }
    };
    ti.addMouseMotionListener(mml);

    String tooltip = ti.getToolTip();

    tray.add(ti);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/* ww  w. j  av  a 2  s  .c  o  m*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);

    PopupMenu popup = new PopupMenu();
    MenuItem miExit = new MenuItem("Exit");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    miExit.addActionListener(al);
    popup.add(miExit);

    TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2");
    ti.setPopupMenu(popup);

    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println(e.getActionCommand());
        }
    };
    ti.setActionCommand("My Icon");
    ti.addActionListener(al);

    MouseListener ml = new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            System.out.println("Tray icon: Mouse clicked");
        }

        public void mouseEntered(MouseEvent e) {
            System.out.println("Tray icon: Mouse entered");
        }

        public void mouseExited(MouseEvent e) {
            System.out.println("Tray icon: Mouse exited");
        }

        public void mousePressed(MouseEvent e) {
            System.out.println("Tray icon: Mouse pressed");
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("Tray icon: Mouse released");
        }
    };
    ti.addMouseListener(ml);
    MouseMotionListener mml = new MouseMotionListener() {
        public void mouseDragged(MouseEvent e) {
            System.out.println("Tray icon: Mouse dragged");
        }

        public void mouseMoved(MouseEvent e) {
            System.out.println("Tray icon: Mouse moved");
        }
    };
    ti.addMouseMotionListener(mml);

    PopupMenu popupMenu = ti.getPopupMenu();

    tray.add(ti);
}