List of usage examples for java.awt Color blue
Color blue
To view the source code for java.awt Color blue.
Click Source Link
From source file:PowerMethod.power_method.java
public static void main(String[] args) { ////////////////////////////////////////////////////// // Edit vals to contain values for matrix A // // Edit vals2 to contain values for initial vector // ////////////////////////////////////////////////////// double[][] vals = { { 3, 4 }, { 3, 1 } }; RealMatrix A = new Array2DRowRealMatrix(vals); double[][] vals2 = { { 1 }, { 1 } }; RealMatrix u = new Array2DRowRealMatrix(vals2); power_object a = power_method(A, u, .1, 7); List<RealMatrix> matrices = genMatrices(); List<trace_det> trace_dets = new ArrayList<>(); double trace; double det;/*from w ww . j ava2 s . co m*/ int iterA; int iterInverseA; for (RealMatrix r : matrices) { MatrixMethods m = new MatrixMethods(r); RealMatrix inverseR = m.inverseMatrix(); power_object largestVal = power_method(r, u, .00005, 100); power_object smallestVal = power_method(inverseR, u, .00005, 100); if (largestVal == null || smallestVal == null) { continue; } trace = m.trace(); det = m.determinant(); iterA = largestVal.getNumN(); iterInverseA = smallestVal.getNumN(); trace_det td = new trace_det(trace, det, iterA, iterInverseA); trace_dets.add(td); } JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant", "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.BLUE); renderer.setSeriesPaint(2, Color.GREEN); renderer.setSeriesPaint(3, Color.BLACK); renderer.setSeriesPaint(4, Color.YELLOW); renderer.setSeriesPaint(5, Color.PINK); renderer.setSeriesPaint(6, Color.ORANGE); renderer.setSeriesPaint(7, Color.GRAY); renderer.setSeriesPaint(8, Color.MAGENTA); renderer.setSeriesPaint(9, Color.LIGHT_GRAY); renderer.setSeriesPaint(10, Color.DARK_GRAY); //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) ); //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) ); plot.setRenderer(renderer); ChartFrame frame = new ChartFrame("Power Method", chart); frame.pack(); frame.setVisible(true); JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method", "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true, false); ChartPanel inverseChartPanel = new ChartPanel(inverseChart); inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); final XYPlot inversePlot = inverseChart.getXYPlot(); XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer(); inverseRenderer.setSeriesPaint(0, Color.RED); inverseRenderer.setSeriesPaint(1, Color.BLUE); inverseRenderer.setSeriesPaint(2, Color.GREEN); inverseRenderer.setSeriesPaint(3, Color.BLACK); inverseRenderer.setSeriesPaint(4, Color.YELLOW); inverseRenderer.setSeriesPaint(5, Color.PINK); inverseRenderer.setSeriesPaint(6, Color.ORANGE); inverseRenderer.setSeriesPaint(7, Color.GRAY); inverseRenderer.setSeriesPaint(8, Color.MAGENTA); inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY); inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY); inversePlot.setRenderer(renderer); ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart); inverseFrame.pack(); inverseFrame.setVisible(true); }
From source file:pl.dpbz.poid.zadanie3.Main.java
public static void main(String args[]) throws UnsupportedAudioFileException, IOException { //Zassanie pliku File f = new File("ExampleSounds/artificial/easy/100Hz.wav"); Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(f); double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(f); //Zwyky sound, ktry nie potrzebuje zespolonych elementw Sound s = new Sound(ints, samplingFrequency); //Obliczenie czstotliwoci przy pomocy fazwki PhaseSpaceMultiDimensional pS = new PhaseSpaceMultiDimensional(s); pS.setupPhaseSpace();/* w ww. j ava2 s. c o m*/ pS.computeFrequency(); System.out.println("Phase space " + pS.getFrequency()); //Zespolony dwik, ktry jest bardziej zoony ComplexSound cs = new ComplexSound(ints, samplingFrequency, 15); //To oblicza fouriera cs.setupElementsOfComplexSound(); //Tutaj obliczanie czstotliwoci przy pomocy fouriera CombFiltering cf = new CombFiltering(cs, samplingFrequency); cf.computeFrequency(); cf.drawComplexSound(); System.out.println("Comb Filtering " + cf.getFrequency()); //Przy sekwencjach nie ma majstrowania przy ustawieniach, uytkownik // zmiennie moe podawa tylko liczb prbek, reszt jak czstotliwo prbkowania // i audio format pobiera si z otwieranego pliku //Test sekwencji na fazie File file = new File("ExampleSounds/seq/DWK_violin.wav"); Integer[] seqInte = WaveToSamplesConverter.convertWaveToIntSamples(file); System.out.println("Samples overview " + seqInte.length); double seqSamplingFrequency = WaveToSamplesConverter.getSamplingFrequency(file); int samplesPerPart = 3000; SamplesToWaveConverter conv = new PhaseSpaceSampleConverter(seqSamplingFrequency, samplesPerPart, WaveToSamplesConverter.getAudioFormat(file)); conv.setupFrequenciesFromSamples(seqInte); System.out.println("Zapisuj"); conv.saveGeneratedSamples("XDPhase.wav"); //Test sekwencji na grzebieniu SamplesToWaveConverter conv2 = new CombFilteringSampleConverter(seqSamplingFrequency, samplesPerPart, WaveToSamplesConverter.getAudioFormat(file)); conv2.setupFrequenciesFromSamples(seqInte); System.out.println("Zapisuj"); conv2.saveGeneratedSamples("XDComb.wav"); //Rysowanie wykresu sygnau dwikowego final XYSeries dist = new XYSeries("P0"); int index = 0; for (Integer i : ints) { dist.add(index / samplingFrequency, i); index++; } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dist); JFreeChart chart = ChartFactory.createXYLineChart(f.getName(), "index", "Distance", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); NumberAxis domain = (NumberAxis) xyPlot.getRangeAxis(); domain.setRange(-32768, 32768); ChartDrawer.drawChart(chart); System.out.println("FINISHED"); }
From source file:Examples.java
public static void main(String args[]) { JFrame frame = new JFrame("Example Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); JFrame frame2 = new JFrame("Desktop"); final JDesktopPane desktop = new JDesktopPane(); frame2.getContentPane().add(desktop); JButton pick = new JButton("Pick"); pick.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hi"); }/*from w w w .j ava2 s . c o m*/ }); frame2.getContentPane().add(pick, BorderLayout.SOUTH); JButton messagePopup = new JButton("Message"); contentPane.add(messagePopup); messagePopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showMessageDialog(source, "Printing complete"); JOptionPane.showInternalMessageDialog(desktop, "Printing complete"); } }); JButton confirmPopup = new JButton("Confirm"); contentPane.add(confirmPopup); confirmPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showConfirmDialog(source, "Continue printing?"); JOptionPane.showInternalConfirmDialog(desktop, "Continue printing?"); } }); JButton inputPopup = new JButton("Input"); contentPane.add(inputPopup); inputPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane.showInputDialog(source, "Enter printer name:"); // Moons of Neptune String smallList[] = { "Naiad", "Thalassa", "Despina", "Galatea", "Larissa", "Proteus", "Triton", "Nereid" }; JOptionPane.showInternalInputDialog(desktop, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, smallList, "Triton"); // Moons of Saturn - includes two provisional designations to // make 20 String bigList[] = { "Pan", "Atlas", "Prometheus", "Pandora", "Epimetheus", "Janus", "Mimas", "Enceladus", "Tethys", "Telesto", "Calypso", "Dione", "Helene", "Rhea", "Titan", "Hyperion", "Iapetus", "Phoebe", "S/1995 S 2", "S/1981 S 18" }; // Object saturnMoon = JOptionPane.showInputDialog(source, "Pick // a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, // bigList, "Titan"); Object saturnMoon = JOptionPane.showInputDialog(source, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, bigList, null); System.out.println("Saturn Moon: " + saturnMoon); } }); JButton optionPopup = new JButton("Option"); contentPane.add(optionPopup); optionPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Icon greenIcon = new DiamondIcon(Color.green); Icon redIcon = new DiamondIcon(Color.red); Object iconArray[] = { greenIcon, redIcon }; JOptionPane.showOptionDialog(source, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, iconArray, iconArray[1]); Icon blueIcon = new DiamondIcon(Color.blue); Object stringArray[] = { "Do It", "No Way" }; JOptionPane.showInternalOptionDialog(desktop, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]); } }); frame.setSize(300, 200); frame.setVisible(true); frame2.setSize(300, 200); frame2.setVisible(true); }
From source file:SimpleMenu.java
/** A simple test program for the above code */ public static void main(String[] args) { // Get the locale: default, or specified on command-line Locale locale;//from w w w .ja v a2 s. c om if (args.length == 2) locale = new Locale(args[0], args[1]); else locale = Locale.getDefault(); // Get the resource bundle for that Locale. This will throw an // (unchecked) MissingResourceException if no bundle is found. ResourceBundle bundle = ResourceBundle.getBundle("com.davidflanagan.examples.i18n.Menus", locale); // Create a simple GUI window to display the menu with final JFrame f = new JFrame("SimpleMenu: " + // Window title locale.getDisplayName(Locale.getDefault())); JMenuBar menubar = new JMenuBar(); // Create a menubar. f.setJMenuBar(menubar); // Add menubar to window // Define an action listener for that our menu will use. ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); Component c = f.getContentPane(); if (s.equals("red")) c.setBackground(Color.red); else if (s.equals("green")) c.setBackground(Color.green); else if (s.equals("blue")) c.setBackground(Color.blue); } }; // Now create a menu using our convenience routine with the resource // bundle and action listener we've created JMenu menu = SimpleMenu.create(bundle, "colors", new String[] { "red", "green", "blue" }, listener); // Finally add the menu to the GUI, and pop it up menubar.add(menu); // Add the menu to the menubar f.setSize(300, 150); // Set the window size. f.setVisible(true); // Pop the window up. }
From source file:Graph_with_jframe_and_arduino.java
public static void main(String[] args) { // create and configure the window JFrame window = new JFrame(); window.setTitle("Sensor Graph GUI"); window.setSize(600, 400);// w w w . j a v a 2 s . co m window.setLayout(new BorderLayout()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create a drop-down box and connect button, then place them at the top of the window JComboBox<String> portList_combobox = new JComboBox<String>(); Dimension d = new Dimension(300, 100); portList_combobox.setSize(d); JButton connectButton = new JButton("Connect"); JPanel topPanel = new JPanel(); topPanel.add(portList_combobox); topPanel.add(connectButton); window.add(topPanel, BorderLayout.NORTH); //pause button JButton Pause_btn = new JButton("Start"); // populate the drop-down box SerialPort[] portNames; portNames = SerialPort.getCommPorts(); //check for new port available Thread thread_port = new Thread() { @Override public void run() { while (true) { SerialPort[] sp = SerialPort.getCommPorts(); if (sp.length > 0) { for (SerialPort sp_name : sp) { int l = portList_combobox.getItemCount(), i; for (i = 0; i < l; i++) { //check port name already exist or not if (sp_name.getSystemPortName().equalsIgnoreCase(portList_combobox.getItemAt(i))) { break; } } if (i == l) { portList_combobox.addItem(sp_name.getSystemPortName()); } } } else { portList_combobox.removeAllItems(); } portList_combobox.repaint(); } } }; thread_port.start(); for (SerialPort sp_name : portNames) portList_combobox.addItem(sp_name.getSystemPortName()); //for(int i = 0; i < portNames.length; i++) // portList.addItem(portNames[i].getSystemPortName()); // create the line graph XYSeries series = new XYSeries("line 1"); XYSeries series2 = new XYSeries("line 2"); XYSeries series3 = new XYSeries("line 3"); XYSeries series4 = new XYSeries("line 4"); for (int i = 0; i < 100; i++) { series.add(x, 0); series2.add(x, 0); series3.add(x, 0); series4.add(x, 10); x++; } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); dataset.addSeries(series2); XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(series3); dataset2.addSeries(series4); //create jfree chart JFreeChart chart = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading", dataset); JFreeChart chart2 = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading 2", dataset2); //color render for chart 1 XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer(); r1.setSeriesPaint(0, Color.RED); r1.setSeriesPaint(1, Color.GREEN); r1.setSeriesShapesVisible(0, false); r1.setSeriesShapesVisible(1, false); XYPlot plot = chart.getXYPlot(); plot.setRenderer(0, r1); plot.setRenderer(1, r1); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.blue); //color render for chart 2 XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer(); r2.setSeriesPaint(0, Color.BLUE); r2.setSeriesPaint(1, Color.ORANGE); r2.setSeriesShapesVisible(0, false); r2.setSeriesShapesVisible(1, false); XYPlot plot2 = chart2.getXYPlot(); plot2.setRenderer(0, r2); plot2.setRenderer(1, r2); ChartPanel cp = new ChartPanel(chart); ChartPanel cp2 = new ChartPanel(chart2); //multiple graph container JPanel graph_container = new JPanel(); graph_container.setLayout(new BoxLayout(graph_container, BoxLayout.X_AXIS)); graph_container.add(cp); graph_container.add(cp2); //add chart panel in main window window.add(graph_container, BorderLayout.CENTER); //window.add(cp2, BorderLayout.WEST); window.add(Pause_btn, BorderLayout.AFTER_LAST_LINE); Pause_btn.setEnabled(false); //pause btn action Pause_btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (Pause_btn.getText().equalsIgnoreCase("Pause")) { if (chosenPort.isOpen()) { try { Output.write(0); } catch (IOException ex) { Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null, ex); } } Pause_btn.setText("Start"); } else { if (chosenPort.isOpen()) { try { Output.write(1); } catch (IOException ex) { Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null, ex); } } Pause_btn.setText("Pause"); } throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // configure the connect button and use another thread to listen for data connectButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (connectButton.getText().equals("Connect")) { // attempt to connect to the serial port chosenPort = SerialPort.getCommPort(portList_combobox.getSelectedItem().toString()); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); if (chosenPort.openPort()) { Output = chosenPort.getOutputStream(); connectButton.setText("Disconnect"); Pause_btn.setEnabled(true); portList_combobox.setEnabled(false); } // create a new thread that listens for incoming text and populates the graph Thread thread = new Thread() { @Override public void run() { Scanner scanner = new Scanner(chosenPort.getInputStream()); while (scanner.hasNextLine()) { try { String line = scanner.nextLine(); int number = Integer.parseInt(line); series.add(x, number); series2.add(x, number / 2); series3.add(x, number / 1.5); series4.add(x, number / 5); if (x > 100) { series.remove(0); series2.remove(0); series3.remove(0); series4.remove(0); } x++; window.repaint(); } catch (Exception e) { } } scanner.close(); } }; thread.start(); } else { // disconnect from the serial port chosenPort.closePort(); portList_combobox.setEnabled(true); Pause_btn.setEnabled(false); connectButton.setText("Connect"); } } }); // show the window window.setVisible(true); }
From source file:ta4jexamples.indicators.CandlestickChart.java
public static void main(String[] args) { /**//from w w w . j ava2 s. c o m * Getting time series */ TimeSeries series = CsvTradesLoader.loadBitstampSeries(); /** * Creating the OHLC dataset */ OHLCDataset ohlcDataset = createOHLCDataset(series); /** * Creating the additional dataset */ TimeSeriesCollection xyDataset = createAdditionalDataset(series); /** * Creating the chart */ JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset, true); // Candlestick rendering CandlestickRenderer renderer = new CandlestickRenderer(); renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); // Additional dataset int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.setRangeGridlinePaint(Color.lightGray); plot.setBackgroundPaint(Color.white); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setAutoRangeIncludesZero(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); /** * Displaying the chart */ displayChart(chart); }
From source file:com.oculusinfo.ml.spark.unsupervised.TestDPMeans.java
/** * @param args//from w w w. j a v a 2s . c om */ public static void main(String[] args) { int k = 5; try { FileUtils.deleteDirectory(new File("output/clusters")); FileUtils.deleteDirectory(new File("output/centroids")); } catch (IOException e1) { /* ignore (*/ } genTestData(k); JavaSparkContext sc = new JavaSparkContext("local", "OculusML"); SparkDataSet ds = new SparkDataSet(sc); ds.load("test.txt", new InstanceParser()); DPMeansClusterer clusterer = new DPMeansClusterer(80, 10, 0.001); clusterer.setOutputPaths("output/centroids", "output/clusters"); clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0)); clusterer.doCluster(ds); try { final List<double[]> instances = readInstances(); final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black, Color.orange, Color.cyan, Color.darkGray, Color.white }; TestDPMeans t = new TestDPMeans(); t.add(new JComponent() { private static final long serialVersionUID = 7920802321066846416L; public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (double[] inst : instances) { int color = (int) inst[0]; g.setColor(colors[color]); Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5); g2.draw(l); } } }); t.setDefaultCloseOperation(EXIT_ON_CLOSE); t.setSize(400, 400); t.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.oculusinfo.ml.spark.unsupervised.TestThresholdClusterer.java
/** * @param args//w w w . j a v a2 s.c o m */ public static void main(String[] args) { int k = 5; try { FileUtils.deleteDirectory(new File("output/clusters")); FileUtils.deleteDirectory(new File("output/centroids")); } catch (IOException e1) { /* ignore (*/ } genTestData(k); JavaSparkContext sc = new JavaSparkContext("local", "OculusML"); SparkDataSet ds = new SparkDataSet(sc); ds.load("test.txt", new InstanceParser()); ThresholdClusterer clusterer = new ThresholdClusterer(80); clusterer.setOutputPaths("output/centroids", "output/clusters"); clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0)); clusterer.doCluster(ds); try { final List<double[]> instances = readInstances(); final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black, Color.orange, Color.cyan, Color.darkGray, Color.white }; TestThresholdClusterer t = new TestThresholdClusterer(); t.add(new JComponent() { private static final long serialVersionUID = -5597119848880912541L; public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (double[] inst : instances) { int color = (int) inst[0]; g.setColor(colors[color]); Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5); g2.draw(l); } } }); t.setDefaultCloseOperation(EXIT_ON_CLOSE); t.setSize(400, 400); t.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.oculusinfo.ml.spark.unsupervised.TestKMeans.java
/** * @param args//www. j ava 2 s. c o m */ public static void main(String[] args) { int k = 5; try { FileUtils.deleteDirectory(new File("output/clusters")); FileUtils.deleteDirectory(new File("output/centroids")); } catch (IOException e1) { /* ignore (*/ } genTestData(k); JavaSparkContext sc = new JavaSparkContext("local", "OculusML"); SparkDataSet ds = new SparkDataSet(sc); ds.load("test.txt", new SparkInstanceParser() { private static final long serialVersionUID = 1L; @Override public Tuple2<String, Instance> call(String line) throws Exception { Instance inst = new Instance(); String tokens[] = line.split(","); NumericVectorFeature v = new NumericVectorFeature("point"); double x = Double.parseDouble(tokens[0]); double y = Double.parseDouble(tokens[1]); v.setValue(new double[] { x, y }); inst.addFeature(v); return new Tuple2<String, Instance>(inst.getId(), inst); } }); KMeansClusterer clusterer = new KMeansClusterer(k, 10, 0.001, "output/centroids", "output/clusters"); clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0)); clusterer.doCluster(ds); try { final List<double[]> instances = readInstances(); final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black, Color.orange, Color.cyan, Color.darkGray, Color.white }; TestKMeans t = new TestKMeans(); t.add(new JComponent() { private static final long serialVersionUID = 2059497051387104848L; public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (double[] inst : instances) { int color = (int) inst[0]; g.setColor(colors[color]); Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5); g2.draw(l); } } }); t.setDefaultCloseOperation(EXIT_ON_CLOSE); t.setSize(400, 400); t.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ArrowIcon.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.add(panel);//from w w w . jav a 2 s . c o m panel.add(new JLabel("north", new ArrowIcon(ArrowIcon.NORTH), JLabel.CENTER)); panel.add(new JLabel("west", new ArrowIcon(ArrowIcon.WEST), JLabel.CENTER)); panel.add(new JLabel("south", new ArrowIcon(ArrowIcon.SOUTH), JLabel.CENTER)); panel.add(new JLabel("east", new ArrowIcon(ArrowIcon.EAST), JLabel.CENTER)); panel.add(new JLabel("east-20", new ArrowIcon(ArrowIcon.EAST, 20, Color.blue), JLabel.CENTER)); frame.pack(); frame.setVisible(true); }