Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Verifier Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextField textField1 = new JTextField();
    JTextField textField2 = new JTextField();
    JTextField textField3 = new JTextField();

    InputVerifier verifier = new InputVerifier() {
        public boolean verify(JComponent comp) {
            boolean returnValue;
            JTextField textField = (JTextField) comp;
            try {
                Integer.parseInt(textField.getText());
                returnValue = true;/* w ww .ja v a  2  s  .c o  m*/
            } catch (NumberFormatException e) {
                returnValue = false;
            }
            return returnValue;
        }
    };

    textField1.setInputVerifier(verifier);
    textField3.setInputVerifier(verifier);

    Container contentPane = frame.getContentPane();
    contentPane.add(textField1, BorderLayout.NORTH);
    contentPane.add(textField2, BorderLayout.CENTER);
    contentPane.add(textField3, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], Integer.parseInt(args[1]));
    GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream());
    String line;/*  w w w  . ja v a 2  s .  c  o m*/
    BufferedReader bis = new BufferedReader(new FileReader(args[2]));
    while (true) {
        try {
            line = bis.readLine();
            if (line == null)
                break;
            line = line + "\n";
            zip.write(line.getBytes(), 0, line.length());
        } catch (Exception e) {
            break;
        }
    }
    zip.finish();
    zip.close();
    sock.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    X509CertSelector selec = new X509CertSelector();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    System.out.println(selec.match(c));
    selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN");

    System.out.println(selec.match(c));

    Calendar cld = Calendar.getInstance();
    int year = Integer.parseInt(args[1]);
    int month = Integer.parseInt(args[2]) - 1;
    int day = Integer.parseInt(args[3]);
    cld.set(year, month, day);/*from  w ww .  jav a 2 s. c  o  m*/
    Date d = cld.getTime();
    selec.setCertificateValid(d);

    System.out.println(selec.match(c));
    BigInteger sn = new BigInteger("1039056963");
    selec.setSerialNumber(sn);

    System.out.println(selec.match(c));
}

From source file:MulticastSniffer.java

public static void main(String[] args) {
    InetAddress ia = null;/*from w w w. j  a v a 2  s. c  o  m*/
    byte[] buffer = new byte[65535];
    DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
    int port = 0;

    // read the address from the command line
    try {
        try {
            ia = InetAddress.getByName(args[0]);
        } catch (UnknownHostException e) {
            System.err.println(e);
        }
        port = Integer.parseInt(args[1]);
    } catch (Exception e) {
        System.err.println(e);
        System.err.println("Usage: java MulticastSniffer mcast-addr port");
        System.exit(1);
    }
    System.out.println("About to join " + ia);

    try {
        MulticastSocket ms = new MulticastSocket(port);
        ms.joinGroup(ia);
        while (true) {
            System.out.println("About to receive...");
            ms.receive(dp);
            String s = new String(dp.getData(), 0, 0, dp.getLength());
            System.out.println(s);
        }
    } catch (SocketException se) {
        System.err.println(se);
    } catch (IOException ie) {
        System.err.println(ie);
    }
}

From source file:com.github.arnabk.App.java

public static void main(String[] args) {

    if (checkParams(args)) {

        final int frequency = Integer.parseInt(StringUtils.trimToEmpty(args[0])); //in minutes
        final BlockingChecker blockingChecker = new BlockingChecker();
        blockingChecker.execute(frequency, args);

    }/*from w w  w .ja  va 2 s . c  om*/

}

From source file:formats.db.fileformats.csv.RunnerCsv.java

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

    CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(',');

    //initialize the CSVParser object

    CSVParser parser = new CSVParser(new FileReader("D:\\customers.csv"), format);

    List<Customers> customersList = new ArrayList<Customers>();
    for (CSVRecord record : parser) {
        Customers customers = new Customers();

        customers.setId_cs(Integer.parseInt(record.get("id_cs")));
        customers.setF_name(record.get("f_name"));
        customers.setL_name(record.get("l_name"));
        customers.setDiscount(Integer.parseInt(record.get("discount")));
        customers.setLicense(record.get("license"));

        customersList.add(customers);/*from   w  ww . ja va2 s. c om*/
    }
    //close the parser
    parser.close();

    System.out.println(customersList);
}

From source file:gomokuserver.GomokuServer.java

/**
 * @param args the command line arguments
 * @throws java.lang.InterruptedException
 *///from  w ww .ja va 2  s . co m
public static void main(String[] args) throws InterruptedException {
    if (args.length != 1) {
        System.out.println("Run with listen portno as argument");
        return;
    }

    int portno = Integer.parseInt(args[0]);
    ServerSocket sc;
    try {
        System.out.print("Creating socket bound to " + portno + " ... ");
        sc = new ServerSocket(portno);

        System.out.println("DONE");
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
        return;
    }
    FrontOffice fo = new FrontOffice();
    Lobby lb = new Lobby();
    fo.setReferalLobby(lb);
    fo.start();
    lb.start();
    while (!interrupted()) {
        try {
            Socket playersocket = sc.accept();
            playersocket.setKeepAlive(true);
            System.out.println("Received client from " + playersocket.getInetAddress());
            fo.handle(playersocket);
        } catch (IOException ex) {
            Logger.getLogger(GomokuServer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    fo.interrupt();
    lb.interrupt();
    fo.join();
    lb.join();
}

From source file:ThreadPoolTest.java

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("Tests the ThreadPool task.");
        System.out.println("Usage: java ThreadPoolTest numTasks numThreads");
        System.out.println("  numTasks - integer: number of task to run.");
        System.out.println("  numThreads - integer: number of threads " + "in the thread pool.");
        return;// www.  j  a v a 2s .  co m
    }
    int numTasks = Integer.parseInt(args[0]);
    int numThreads = Integer.parseInt(args[1]);

    // create the thread pool
    ThreadPool threadPool = new ThreadPool(numThreads);

    // run example tasks
    for (int i = 0; i < numTasks; i++) {
        threadPool.runTask(createTask(i));
    }

    // close the pool and wait for all tasks to finish.
    threadPool.join();
}

From source file:main.StratioENEI.java

/**
 * @param args the command line arguments
 *//*from  w  w  w.  j a  v  a2 s  . c  om*/
public static void main(String[] args) throws IOException {
    // TODO code application logic here
    float[][] custos;
    List<String> ordem;
    List<String> cidades;
    float custoTotal;
    int nCidades = Integer.parseInt(args[0]);
    String cidadeInicial = args[1];
    String cidadeFinal = args[2];

    for (Mode m : Mode.values()) {
        custos = new float[nCidades][nCidades];
        cidades = new ArrayList<>(nCidades);
        ordem = new ArrayList<>(nCidades);
        readFromCSV(m.file, custos, cidades);

        custoTotal = calculate(custos, cidades.indexOf(cidadeInicial), cidades.indexOf(cidadeFinal), ordem);

        printRota(custoTotal, cidadeInicial, cidadeFinal, cidades, ordem, m);
    }
}

From source file:FactComputer.java

public static void main(String[] args) {
    // Try to compute a factorial.
    // If something goes wrong, handle it in the catch clause below.
    try {// w  w  w . j av a2 s  .  c om
        int x = Integer.parseInt(args[0]);
        System.out.println(x + "! = " + Factorial4.factorial(x));
    }
    // The user forgot to specify an argument.
    // Thrown if args[0] is undefined.
    catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("You must specify an argument");
        System.out.println("Usage: java FactComputer <number>");
    }
    // The argument is not a number. Thrown by Integer.parseInt().
    catch (NumberFormatException e) {
        System.out.println("The argument you specify must be an integer");
    }
    // The argument is < 0. Thrown by Factorial4.factorial()
    catch (IllegalArgumentException e) {
        // Display the message sent by the factorial() method:
        System.out.println("Bad argument: " + e.getMessage());
    }
}