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:Toolbars.java

public static void main(String[] args) {
    JToolBar toolbar1 = new JToolBar();
    JToolBar toolbar2 = new JToolBar();

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JButton newb = new JButton(new ImageIcon("new.png"));
    JButton openb = new JButton(new ImageIcon("open.png"));
    JButton saveb = new JButton(new ImageIcon("save.png"));

    toolbar1.add(newb);//from w w w  .  jav  a  2s. c  om
    toolbar1.add(openb);
    toolbar1.add(saveb);
    toolbar1.setAlignmentX(0);

    JButton exitb = new JButton(new ImageIcon("exit.png"));
    toolbar2.add(exitb);
    toolbar2.setAlignmentX(0);

    exitb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    panel.add(toolbar1);
    panel.add(toolbar2);

    JFrame f = new JFrame();
    f.add(panel, BorderLayout.NORTH);

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

License:asdf

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
        return;// w ww .j  ava  2 s.c  o  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) {
            System.out.println("asdf");
        }
    });
    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);

    image = toolkit.getImage("anotherImage.jpg");
    icon.setImage(image);
    tray.add(icon);
}

From source file:com.rackspacecloud.client.cloudfiles.sample.FilesRemove.java

public static void main(String args[]) throws NoSuchAlgorithmException, FilesException {
    //Build the command line options
    Options options = addCommandLineOptions();

    if (args.length <= 0)
        printHelp(options);/* www. ja v  a2 s .com*/

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("help")) {
            printHelp(options);
            System.exit(0);
        }

        if (line.hasOption("container")) {
            String containerName = null;
            containerName = line.getOptionValue("container");
            removeContainer(containerName, line.hasOption('r'));
        } //if (line.hasOption("container"))

        if (line.hasOption("object")) {
            String ObjectNameWithPath = null;
            ObjectNameWithPath = line.getOptionValue("object");
            removeObject(ObjectNameWithPath);
        } //if (line.hasOption("container"))

    } //end try
    catch (ParseException err) {
        logger.fatal("Parsing exception on the command line: " + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
        err.printStackTrace(System.err);
    } //catch( ParseException err )
    catch (Exception err) {
        logger.fatal("Exception : " + err);
        System.err.println("Please see the logs for more details. Error Message: " + err.getMessage());
    } //catch ( IOException err)
}

From source file:com.dhenton9000.batik.sandbox.BatikExplorer.java

public static void main(String[] args) throws Exception {

    //simpleCreate();
    BatikExplorer p = new BatikExplorer();
    try {/*from   www. j a v  a 2s  .co  m*/
        // p.testOutBatikTranscoder();
        p.testOutPPTX();
        LOG.info("done");
        System.exit(0);
    } catch (Exception e) {
        LOG.error("MAIN ERROR: " + e.getMessage() + "\n", e);
    }
}

From source file:DrawPolyPanel.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("DrawPoly");
    frame.setSize(350, 250);/*from   w ww  .j a va 2s .  com*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    Container contentPane = frame.getContentPane();
    contentPane.add(new DrawPolyPanel());

    frame.show();
}

From source file:com.opengamma.integration.tool.holiday.HolidayQueryTool.java

/**
 * Main method to run the tool.// w  ww  .  ja v  a 2  s .co  m
 */
public static void main(String[] args) { // CSIGNORE
    new HolidayQueryTool().initAndRun(args, ToolContext.class);
    System.exit(0);
}

From source file:ProgressInputSample.java

public static void main(String args[]) {
    int returnValue = NORMAL;
    try {// w  w  w . j a v  a  2s. com
        FileInputStream fis = new FileInputStream("person.xml");
        JLabel filenameLabel = new JLabel("persion.xml", JLabel.RIGHT);
        Object message[] = { "Reading:", filenameLabel };
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
        InputStreamReader isr = new InputStreamReader(pmis);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    } catch (Exception exception) {
        returnValue = PROBLEM;
    }
    System.exit(returnValue);
}

From source file:GetAppInfo.java

/**
 * @param args//from   w  ww .j  a  v a  2s.c om
 */
public static void main(String[] args) {
    if (args.length != 4) {
        System.out.println("Usage :\n" + "java -jar this_jar_name confpath query_str startIndex numbers");
        System.exit(1);
    }
    String confpath = args[0];
    GetAppConfig conf = new GetAppConfig(confpath);
    String email = conf.getUserID();
    String password = conf.getPassword();
    String query = args[1];
    final int startIndex = Integer.parseInt(args[2]);
    final int numbers = Integer.parseInt(args[3]);
    String androidid = conf.getDeviceID();

    if (email.equals("")) {
        System.out.println("Error: Failed to get UserID.");
        System.exit(2);
    } else if (password.equals("")) {
        System.out.println("Error: Failed to get Password.");
        System.exit(3);
    } else if (androidid.equals("")) {
        System.out.println("Error: Failed to get DeviceID.");
        System.exit(4);
    }

    System.out.println("query: " + query);
    MarketSession session = new MarketSession();
    session.getContext().setAndroidId(androidid);

    Locale locale = new Locale("ja", "JP");
    session.setLocale(locale);
    session.setOperator("NTT DOCOMO", "44010");
    session.getContext().setDeviceAndSdkVersion("passion:8");

    try {
        session.login(email, password, androidid);
    } catch (Exception e) {
        System.out.println("Error: failed to login.: " + e.getMessage());
        System.exit(1);
    }

    AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(startIndex)
            .setEntriesCount(numbers).setWithExtendedInfo(true).build();

    Callback<AppsResponse> callback = new Callback<AppsResponse>() {
        @Override
        public void onResult(ResponseContext context, AppsResponse response) {
            int totalcnt, cnt;
            JsonFactory factory = new JsonFactory();
            try {
                JsonGenerator generator = factory.createGenerator(new FileWriter(new File("pkginfo.json")));
                generator.writeStartObject();
                //generator.setRootValueSeparator(new SerializedString("\n"));

                if (response != null) {
                    totalcnt = response.getEntriesCount();
                    cnt = response.getAppCount();
                    System.out.println("startIndex = " + startIndex);
                    System.out.println("entriesCount = " + numbers);
                    System.out.println("totalcount = " + totalcnt);
                    System.out.println("count = " + cnt);
                    generator.writeNumberField("startIndex", startIndex);
                    generator.writeNumberField("entriesCount", numbers);
                    generator.writeNumberField("total", totalcnt);
                    generator.writeNumberField("count", cnt);
                    generator.writeRaw("\n");
                } else {
                    cnt = -1;
                }
                generator.writeFieldName("dataset");
                generator.writeStartArray();

                if (cnt > 0) {
                    for (int i = 0; ((i < cnt) && (i < numbers)); i++) {
                        generator.writeStartObject();
                        generator.writeNumberField("num", i + startIndex);
                        System.out.println(
                                "------------------------------------------------------------------------------------");
                        int counter = i + startIndex;
                        System.out.println(counter + ":");
                        System.out.println(
                                "------------------------------------------------------------------------------------");
                        generator.writeStringField("title", response.getApp(i).getTitle());
                        generator.writeStringField("appType", "" + response.getApp(i).getAppType());
                        generator.writeStringField("category",
                                response.getApp(i).getExtendedInfo().getCategory());
                        generator.writeStringField("rating", response.getApp(i).getRating());
                        generator.writeNumberField("ratingCount", response.getApp(i).getRatingsCount());
                        generator.writeStringField("countText",
                                response.getApp(i).getExtendedInfo().getDownloadsCountText());
                        generator.writeStringField("creatorId", response.getApp(i).getCreatorId());
                        generator.writeStringField("id", response.getApp(i).getId());
                        generator.writeStringField("packageName", response.getApp(i).getPackageName());
                        generator.writeStringField("version", response.getApp(i).getVersion());
                        generator.writeNumberField("versionCode", response.getApp(i).getVersionCode());
                        generator.writeStringField("price", response.getApp(i).getPrice());
                        generator.writeNumberField("priceMicros", response.getApp(i).getPriceMicros());
                        generator.writeStringField("priceCurrency", response.getApp(i).getPriceCurrency());
                        generator.writeStringField("contactWebsite",
                                response.getApp(i).getExtendedInfo().getContactWebsite());
                        generator.writeNumberField("screenshotsCount",
                                response.getApp(i).getExtendedInfo().getScreenshotsCount());
                        generator.writeNumberField("installSize",
                                response.getApp(i).getExtendedInfo().getInstallSize());
                        generator.writeStringField("permissionIdList",
                                "" + response.getApp(i).getExtendedInfo().getPermissionIdList());
                        generator.writeStringField("promotoText",
                                response.getApp(i).getExtendedInfo().getPromoText());
                        generator.writeStringField("description",
                                response.getApp(i).getExtendedInfo().getDescription());

                        System.out.println("title: " + response.getApp(i).getTitle());
                        System.out.println("appType: " + response.getApp(i).getAppType());
                        System.out.println("category: " + response.getApp(i).getExtendedInfo().getCategory());
                        System.out.println("rating: " + response.getApp(i).getRating());
                        System.out.println("ratingsCount: " + response.getApp(i).getRatingsCount());
                        System.out
                                .println("count: " + response.getApp(i).getExtendedInfo().getDownloadsCount());
                        System.out.println(
                                "countText: " + response.getApp(i).getExtendedInfo().getDownloadsCountText());
                        System.out.println("creator: " + response.getApp(i).getCreator());
                        System.out.println("creatorId: " + response.getApp(i).getCreatorId());
                        System.out.println("id: " + response.getApp(i).getId());
                        System.out.println("packageName: " + response.getApp(i).getPackageName());
                        System.out.println("version: " + response.getApp(i).getVersion());
                        //System.out.println("contactEmail: " + response.getApp(i).getExtendedInfo().getContactEmail());
                        //System.out.println("contactPhone: " + response.getApp(i).getExtendedInfo().getContactPhone());
                        System.out.println(
                                "installSize: " + response.getApp(i).getExtendedInfo().getInstallSize());
                        generator.writeEndObject();
                        generator.writeRaw("\n");
                    }
                } else if (cnt == 0) {
                    System.out.println("no hit");
                } else {
                    System.out.println("Bad Reqeust");
                }

                generator.writeEndArray();
                generator.writeEndObject();
                generator.close();

            } catch (Exception e) {
                System.out.println("Error: pkginfo(): " + e.getMessage());
            }

        } // onResult()
    };
    session.append(appsRequest, callback);
    session.flush();
}

From source file:UpdateRecordsUsingPreparedStatement.java

public static void main(String[] args) throws Exception {
    Connection conn = null;/*ww w . j  a  v a  2  s .  com*/
    PreparedStatement pstmt = null;
    try {
        conn = getConnection();
        String query = "update dept set DEPT_LOC = ? where DEPT_NUM = ? ";
        pstmt = conn.prepareStatement(query); // create a statement
        pstmt.setString(1, "deptLocation"); // set input parameter 1
        pstmt.setInt(2, 1001); // set input parameter 2
        pstmt.executeUpdate(); // execute update statement
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        pstmt.close();
        conn.close();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    try {/*  w  w w .jav a 2  s  . c  om*/
        String url = "jdbc:odbc:yourdatabasename";
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String user = "guest";
        String password = "guest";

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);

        Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

        String sqlQuery = "SELECT EMPNO, EName, Job, MGR, HIREDATE FROM EMP";

        ResultSet rs = stmt.executeQuery(sqlQuery);

        int rowSize = 0;
        while (rs.next()) {
            rowSize++;
        }

        System.out.println("Number of Rows in ResultSet is: " + rowSize);
        if (rowSize == 0) {
            System.out.println("Since there are no rows, exiting...");
            System.exit(0);
        }

        int cursorPosition = Math.round(rowSize / 2);

        System.out.println("Moving to position: " + cursorPosition);
        rs.absolute(cursorPosition);
        System.out.println("Name: " + rs.getString(2));

        rs.relative(-1);

        cursorPosition = rs.getRow();
        System.out.println("Moving to position: " + cursorPosition);
        System.out.println("Name: " + rs.getString(2));

        System.out.println("Moving to the first row");
        while (!rs.isFirst()) {
            rs.previous();
        }
        System.out.println("Name: " + rs.getString(2));
        connection.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}