List of usage examples for java.lang Integer Integer
@Deprecated(since = "9") public Integer(String s) throws NumberFormatException
From source file:RedundancyChecker.java
public RedundancyChecker() { Integer[] array = new Integer[5]; // Create and // array of// w ww . j a v a 2 s . c om // Integer Integer i0 = new Integer(0); array[0] = i0; Integer i1 = new Integer(1); // <-------- array[1] = i1; // | Integer i2 = new Integer(2); // |--- redundant // values array[2] = i2; // | Integer i3 = new Integer(1); // <-------- array[3] = i3; Integer i4 = new Integer(4); array[4] = i4; // transform the array into a List List l = Arrays.asList(array); // Check the List checkForRedundancy(l); }
From source file:Main.java
public Main() { super("LayeredPane"); setSize(200, 150);//w w w .ja v a2 s.c om setDefaultCloseOperation(EXIT_ON_CLOSE); JLayeredPane lp = getLayeredPane(); // Create 3 buttons JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); // Place the buttons in different layers lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1)); }
From source file:MainClass.java
public MainClass() throws Exception { getContentPane().setLayout(new BorderLayout()); Object[][] data = { { "A", "B", "C", new Integer(5), new Boolean(false) }, { "D", "E", "F", new Integer(3), new Boolean(true) } }; String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; table = new JTable(data, columnNames); JPanel tPanel = new JPanel(new BorderLayout()); tPanel.add(table.getTableHeader(), BorderLayout.NORTH); tPanel.add(table, BorderLayout.CENTER); getContentPane().add(tPanel, BorderLayout.CENTER); Document document = new Document(); PdfWriter writer;/*from w ww . j a va2 s . c o m*/ writer = PdfWriter.getInstance(document, new FileOutputStream("my_jtable_shapes.pdf")); // writer = PdfWriter.getInstance(document, new // FileOutputStream("my_jtable_fonts.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(500, 500); Graphics2D g2; g2 = tp.createGraphicsShapes(500, 500); // g2 = tp.createGraphics(500, 500); table.print(g2); g2.dispose(); cb.addTemplate(tp, 30, 300); // step 5: we close the document document.close(); }
From source file:NumberFormatDemo.java
static public void displayNumber(Locale currentLocale) { Integer quantity = new Integer(123456); Double amount = new Double(345987.246); NumberFormat numberFormatter; String quantityOut;/*from www. j av a2s . co m*/ String amountOut; numberFormatter = NumberFormat.getNumberInstance(currentLocale); quantityOut = numberFormatter.format(quantity); amountOut = numberFormatter.format(amount); System.out.println(quantityOut + " " + currentLocale.toString()); System.out.println(amountOut + " " + currentLocale.toString()); }
From source file:SessionSnoop.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); Integer count = (Integer) session.getAttribute("count"); if (count == null) count = new Integer(1); else// w w w . j ava 2 s. c o m count = new Integer(count.intValue() + 1); session.setAttribute("count", count); out.println("<HTML><HEAD><TITLE>Session Count</TITLE></HEAD>"); out.println("<BODY><H1>Session Count</H1>"); out.println("You've visited this page " + count + ((count == 1) ? " time." : " times.")); out.println("<P>"); out.println("<H3>Here is your saved session data:</H3>"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println(name + ": " + session.getAttribute(name) + "<BR>"); } out.println("<H3>Here are some vital stats on your session:</H3>"); out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>"); out.println("New session: " + session.isNew() + "<BR>"); out.println("Timeout: " + session.getMaxInactiveInterval()); out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>"); out.println("Creation time: " + session.getCreationTime()); out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>"); out.println("Last access time: " + session.getLastAccessedTime()); out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>"); out.println("Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>"); out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>"); out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>"); out.println("<H3>Test URL Rewriting</H3>"); out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>"); out.println("to test that session tracking works via URL"); out.println("rewriting even when cookies aren't supported."); out.println("</BODY></HTML>"); }
From source file:Main.java
/** * Creates a {@link TransformerHandler}. * /* w w w. ja va2s .c o m*/ * @param commentHeader the comment header * @param rootTag the root tag * @param streamResult stream result */ public static TransformerHandler createTransformerHandler(String commentHeader, String rootTag, StreamResult streamResult, Charset charset) throws TransformerFactoryConfigurationError, TransformerConfigurationException, SAXException { SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance(); try { tf.setAttribute("indent-number", new Integer(2)); } catch (Exception e) { // ignore, workaround for JDK 1.5 bug, see http://forum.java.sun.com/thread.jspa?threadID=562510 } TransformerHandler transformerHandler = tf.newTransformerHandler(); Transformer serializer = transformerHandler.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, charset.name()); serializer.setOutputProperty(OutputKeys.METHOD, "xml"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); transformerHandler.setResult(streamResult); transformerHandler.startDocument(); String newline = System.getProperty("line.separator"); if (newline == null) { newline = "\n"; } commentHeader = (newline + commentHeader).replaceAll("\\n--", newline + " "); transformerHandler.characters("\n".toCharArray(), 0, 1); transformerHandler.comment(commentHeader.toCharArray(), 0, commentHeader.toCharArray().length); transformerHandler.characters("\n".toCharArray(), 0, 1); if (rootTag.length() > 0) { transformerHandler.startElement("", "", rootTag, null); } return transformerHandler; }
From source file:Main.java
/** * Convert to base 128 (bigendian), using shifts. * @param val/*w ww.j av a2s . c o m*/ * @return */ public static ArrayList<Integer> base128(BigInteger val) { ArrayList<Integer> result = new ArrayList<Integer>(); int part = val.and(BN127).intValue(); val = val.shiftRight(7); result.add(0, new Integer(part)); while (!val.equals(BigInteger.ZERO)) { part = val.and(BN127).intValue(); val = val.shiftRight(7); part += 128; result.add(0, new Integer(part)); } ; return result; }
From source file:Main.java
/** * Saves a DOM to a human-readable XML file (4-space indentation, UTF-8). * <p>//from w ww. j a v a 2s. co m * Contains workaround for various JVM bugs. * * @param document * The DOM * @param file * The target XML file * @throws TransformerFactoryConfigurationError * In case of an XML transformation factory configuration error * @throws TransformerException * In case of an XML transformation error * @throws IOException * In case of an I/O error */ public static void saveHumanReadable(Document document, File file) throws TransformerFactoryConfigurationError, TransformerException, IOException { // Various indentation and UTF8 encoding bugs are worked around here TransformerFactory factory = TransformerFactory.newInstance(); factory.setAttribute("indent-number", new Integer(4)); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF8"); transformer.transform(new DOMSource(document), new StreamResult(writer)); writer.close(); }
From source file:SimpleInternalFrame.java
public SimpleInternalFrame() { super(""); setSize(500, 400);/*from w w w . j a va2 s.c o m*/ desktop = new JDesktopPane(); desktop.setOpaque(true); add(desktop, BorderLayout.CENTER); internalFrame = new JInternalFrame("Meow", true, true, true, true); internalFrame.setBounds(50, 50, 200, 100); internalFrame.getContentPane().add(new JLabel(new ImageIcon("1.jpg"))); internalFrame.setVisible(true); desktop.add(internalFrame, new Integer(1)); }
From source file:Counter.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(true); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); int count = 1; Integer i = (Integer) session.getAttribute(COUNTER_KEY); if (i != null) { count = i.intValue() + 1;/*from w w w .j a v a2 s . c o m*/ } session.setAttribute(COUNTER_KEY, new Integer(count)); out.println("<html>"); out.println("<head>"); out.println("<title>Session Counter</title>"); out.println("</head>"); out.println("<body>"); out.println("Your session ID is <b>" + session.getId()); out.println("</b> and you have hit this page <b>" + count + "</b> time(s) during this browser session"); out.println("<form method=GET action=\"" + req.getRequestURI() + "\">"); out.println("<input type=submit " + "value=\"Hit page again\">"); out.println("</form>"); out.println("</body>"); out.println("</html>"); out.flush(); }