List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }/*from ww w . j a va 2 s. c o m*/ } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); Enumeration e = table.getColumnModel().getColumns(); TableColumn col = (TableColumn) e.nextElement(); col.setCellRenderer(table.getDefaultRenderer(Boolean.class)); col.setCellEditor(table.getDefaultEditor(Boolean.class)); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:SortByMark.java
public static void main(String args[]) { List<Student> students = new ArrayList<Student>(); SortByMark sortByMark = new SortByMark(); students.add(new Student("A", new Double(34.34))); students.add(new Student("C", new Double(123.22))); students.add(new Student("B", new Double(13.00))); students.add(new Student("Z", new Double(99.22))); students.add(new Student("X", new Double(-19.08))); Collections.sort(students, sortByMark); for (Student student : students) { System.out.println(student); }//from w w w . j a v a 2 s .co m }
From source file:FloatCmp.java
public static void main(String[] argv) { double da = 3 * .3333333333; double db = 0.99999992857; // Compare two numbers that are expected to be close. if (da == db) { System.out.println("Java considers " + da + "==" + db); // else compare with our own equals method } else if (equals(da, db, 0.0000001)) { System.out.println("True within epsilon " + EPSILON); } else {/*from w ww. j av a 2 s . co m*/ System.out.println(da + " != " + db); } // Show that comparing two NaNs is not a good idea: double d1 = Double.NaN; double d2 = Double.NaN; if (d1 == d2) System.err.println("Comparing two NaNs incorrectly returns true."); if (!new Double(d1).equals(new Double(d2))) System.err.println("Double(NaN).equal(NaN) incorrectly returns false."); }
From source file:ArrayEnumerationFactory.java
public static void main(String args[]) { Enumeration e = makeEnumeration(args); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }// www . j a v a 2 s . com e = makeEnumeration(new int[] { 1, 3, 4, 5 }); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } try { e = makeEnumeration(new Double(Math.PI)); } catch (IllegalArgumentException ex) { System.err.println("Can't enumerate that: " + ex.getMessage()); } }
From source file:ArraysTester.java
public static void main(String[] args) { ArraysTester tester = new ArraysTester(50); int[] myArray = tester.get(); // Compare two arrays int[] myOtherArray = tester.get().clone(); if (Arrays.equals(myArray, myOtherArray)) { System.out.println("The two arrays are equal!"); } else {//from ww w . java 2 s . c o m System.out.println("The two arrays are not equal!"); } // Fill up some values Arrays.fill(myOtherArray, 2, 10, new Double(Math.PI).intValue()); myArray[30] = 98; // Print array, as is System.out.println("Here's the unsorted array..."); System.out.println(Arrays.toString(myArray)); System.out.println(); // Sort the array Arrays.sort(myArray); // print array, sorted System.out.println("Here's the sorted array..."); System.out.println(Arrays.toString(myArray)); System.out.println(); // Get the index of a particular value int index = Arrays.binarySearch(myArray, 98); System.out.println("98 is located in the array at index " + index); String[][] ticTacToe = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } }; System.out.println(Arrays.deepToString(ticTacToe)); String[][] ticTacToe2 = { { "O", "O", "X" }, { "O", "X", "X" }, { "X", "O", "X" } }; String[][] ticTacToe3 = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } }; if (Arrays.deepEquals(ticTacToe, ticTacToe2)) { System.out.println("Boards 1 and 2 are equal."); } else { System.out.println("Boards 1 and 2 are not equal."); } if (Arrays.deepEquals(ticTacToe, ticTacToe3)) { System.out.println("Boards 1 and 3 are equal."); } else { System.out.println("Boards 1 and 3 are not equal."); } }
From source file:Main.java
public static void main(String[] args) throws Exception { int SIZE = 14; String FONT = "Dialog"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane tp = new JTextPane(); tp.setFont(new Font(FONT, Font.PLAIN, SIZE)); tp.setPreferredSize(new Dimension(400, 300)); StyledDocument doc = tp.getStyledDocument(); Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style boldStyle = doc.addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); String boldText = "this is bold test"; String plainText = "this is plain."; doc.insertString(doc.getLength(), boldText, boldStyle); doc.insertString(doc.getLength(), plainText, defaultStyle); JPanel panel = new JPanel(); panel.add(tp);/* ww w .j a v a 2 s . c o m*/ JComboBox<String> zoomCombo = new JComboBox<String>( new String[] { "0.75", "1.00", "1.50", "1.75", "2.00" }); zoomCombo.addActionListener(e -> { String s = (String) zoomCombo.getSelectedItem(); double scale = new Double(s).doubleValue(); int size = (int) (SIZE * scale); tp.setFont(new Font(FONT, Font.PLAIN, size)); }); zoomCombo.setSelectedItem("1.00"); JPanel optionsPanel = new JPanel(); optionsPanel.add(zoomCombo); panel.setBackground(Color.WHITE); frame.add(panel, BorderLayout.CENTER); frame.add(optionsPanel, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); }
From source file:NumberDemo.java
public static void main(String args[]) { Float one = new Float(14.78f - 13.78f); Float oneAgain = Float.valueOf("1.0"); Double doubleOne = new Double(1.0); int difference = one.compareTo(oneAgain); if (difference == 0) { System.out.println("one is equal to oneAgain."); } else if (difference < 0) { System.out.println("one is less than oneAgain."); } else if (difference > 0) { System.out.println("one is greater than oneAgain."); }// w w w.j a v a 2s .c om System.out.println("one is " + ((one.equals(doubleOne)) ? "equal" : "not equal") + " to doubleOne."); }
From source file:org.jfree.chart.demo.ImageMapDemo2.java
/** * The starting point for the demo./*from ww w . j a v a 2 s .c o m*/ * * @param args ignored. */ public static void main(final String[] args) { // create a chart final DefaultPieDataset data = new DefaultPieDataset(); data.setValue("One", new Double(43.2)); data.setValue("Two", new Double(10.0)); data.setValue("Three", new Double(27.5)); data.setValue("Four", new Double(17.5)); data.setValue("Five", new Double(11.0)); data.setValue("Six", new Double(19.4)); JFreeChart chart = null; final boolean drilldown = true; // create the chart... if (drilldown) { final PiePlot plot = new PiePlot(data); // plot.setInsets(new Insets(0, 5, 5, 5)); plot.setToolTipGenerator(new StandardPieItemLabelGenerator()); plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp")); chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title data, // data true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("piechart100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("piechart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo 2</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"piechart100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:cn.edu.thss.iise.bpmdemo.charts.ThermometerDemo2.java
/** * Starting point for the demonstration application. * * @param args/*from w ww .j av a 2s.c om*/ * ignored. * @throws InterruptedException */ public static void main(final String[] args) throws InterruptedException { ThermometerDemo2 demo = new ThermometerDemo2("Thermometer Demo 2"); demo.pack(); demo.setVisible(true); int i = 0; for (i = 0; i < 10; i++) { Thread.sleep(1000); demo.dataset.setValue(new Double(new Double(10.0 * i))); } }
From source file:org.jfree.chart.demo.PerformanceTest1.java
public static void main(String args[]) { ArrayList<Double> arraylist = new ArrayList<Double>(); for (int i = 0; i < 4000; i++) arraylist.add(new Double(Math.random())); int j = 0;/*ww w .j ava2 s. c o m*/ for (int k = 0; k < 20000; k++) { long l = System.currentTimeMillis(); for (int i1 = 0; i1 < 0xf4240; i1++) j += i1; long l1 = System.currentTimeMillis(); System.out.println(k + " --> " + (l1 - l) + " (" + Runtime.getRuntime().freeMemory() + " / " + Runtime.getRuntime().totalMemory() + ")"); } }