List of usage examples for java.awt Color green
Color green
To view the source code for java.awt Color green.
Click Source Link
From source file:G2DCircleIntersectPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww. j a va 2 s. co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("G2DCircleIntersectPDF.pdf")); document.open(); DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); mapper.insertDirectory("c:\\windows\\fonts"); int w = 150; int h = 150; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h, mapper); tp.setWidth(w); tp.setHeight(h); double ew = w / 2; double eh = h / 2; Ellipse2D.Double circle, circle1; circle = new Ellipse2D.Double(ew - 16, eh - 29, 50.0, 50.0); g2.setColor(Color.green); g2.fill(circle); g2.setColor(Color.red); circle1 = new Ellipse2D.Double(ew, eh, 50.0, 50.0); g2.fill(circle1); Area area1 = new Area(circle); Area area2 = new Area(circle1); g2.setColor(Color.BLUE); area1.intersect(area2); g2.fill(area1); g2.dispose(); cb.addTemplate(tp, 50, 400); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:StylesExample2.java
public static void main(String[] args) { try {//ww w. j a va2 s. co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Styles Example 2"); // Create the StyleContext, the document and the pane StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); JTextPane pane = new JTextPane(doc); // Create and add the main document style Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); final Style mainStyle = sc.addStyle("MainStyle", defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style final Style cwStyle = sc.addStyle("ConstantWidth", null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style final Style heading2Style = sc.addStyle("Heading2", null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { // Set the logical style doc.setLogicalStyle(0, mainStyle); // Add the text to the document doc.insertString(0, text, null); // Apply the character attributes doc.setCharacterAttributes(49, 13, cwStyle, false); doc.setCharacterAttributes(223, 14, cwStyle, false); doc.setCharacterAttributes(249, 14, cwStyle, false); doc.setCharacterAttributes(286, 8, cwStyle, false); doc.setCharacterAttributes(475, 14, cwStyle, false); doc.setCharacterAttributes(497, 21, cwStyle, false); doc.setCharacterAttributes(557, 9, cwStyle, false); doc.setCharacterAttributes(639, 12, cwStyle, false); doc.setCharacterAttributes(733, 21, cwStyle, false); doc.setCharacterAttributes(759, 9, cwStyle, false); // Finally, apply the style to the heading doc.setParagraphAttributes(0, 1, heading2Style, false); } catch (BadLocationException e) { } } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:ColorComboBox.java
public static void main(String args[]) { Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow }; JFrame frame = new JFrame("Color JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JComboBox comboBox = new JComboBox(colors); comboBox.setMaximumRowCount(5);/*from w w w. j av a2 s. c om*/ comboBox.setEditable(true); comboBox.setRenderer(new ColorCellRenderer()); Color color = (Color) comboBox.getSelectedItem(); ComboBoxEditor editor = new ColorComboBoxEditor(color); comboBox.setEditor(editor); contentPane.add(comboBox, BorderLayout.NORTH); final JLabel label = new JLabel(); label.setOpaque(true); label.setBackground((Color) comboBox.getSelectedItem()); contentPane.add(label, BorderLayout.CENTER); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color selectedColor = (Color) comboBox.getSelectedItem(); label.setBackground(selectedColor); } }; comboBox.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ComplexCellRenderer.java
public static void main(String args[]) { Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" }, { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" }, { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" }, { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ListCellRenderer renderer = new ComplexCellRenderer(); JComboBox comboBox = new JComboBox(elements); comboBox.setRenderer(renderer);/*from ww w. j a v a 2 s . co m*/ frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ComplexCellRenderer.java
public static void main(String args[]) { Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" }, { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" }, { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" }, { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(elements); ListCellRenderer renderer = new ComplexCellRenderer(); jlist.setCellRenderer(renderer);//from www . j ava2 s .co m JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ComboTableCellRenderer.java
public static void main(String args[]) { Color choices[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA }; ComboTableCellRenderer renderer = new ComboTableCellRenderer(); JComboBox comboBox = new JComboBox(choices); comboBox.setRenderer(renderer);/*from w w w . j a v a 2s. c o m*/ TableCellEditor editor = new DefaultCellEditor(comboBox); JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(1); column.setCellRenderer(renderer); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:ega.projekt.graphDraw.DrawGraph.java
/** * @param args the command line arguments */// www.ja v a2 s. co m public static void main(String[] args) { ega.projekt.graph.Graph dataGraph = new ega.projekt.graph.Graph(5, 100, 295, 295); if (dataGraph.getEdges().isEmpty()) System.out.println("Error initializing graph"); DrawGraph graphView = new DrawGraph(dataGraph); // This builds the graph // Layout<V, E>, VisualizationComponent<V,E> Layout<Node, Edge> layout = new StaticLayout(graphView.drawGraph); for (Node n : graphView.drawGraph.getVertices()) { layout.setLocation(n, new java.awt.geom.Point2D.Double(n.getX(), n.getY())); } layout.setSize(new Dimension(300, 300)); BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<>(layout); vv.setPreferredSize(new Dimension(350, 350)); // Setup up a new vertex to paint transformer... Transformer<Node, Paint> vertexPaint = new Transformer<Node, Paint>() { public Paint transform(Node i) { return Color.GREEN; } }; // Set up a new stroke Transformer for the edges //float dash[] = {10.0f}; final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); Transformer<Edge, Stroke> edgeStrokeTransformer = new Transformer<Edge, Stroke>() { public Stroke transform(Edge e) { if (e.isMarked()) { final Stroke modStroke = new BasicStroke(5.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); return modStroke; } return edgeStroke; } }; Transformer<Edge, Paint> edgePaint = new Transformer<Edge, Paint>() { public Paint transform(Edge e) { if (e.isMarked()) { return Color.RED; } return Color.BLACK; } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Node, Edge>()); vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() { public String transform(Edge e) { return (e.getFlowString() + "/" + Integer.toString(e.getCapacity())); } }); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Node, String>() { public String transform(Node n) { return (Integer.toString(n.getID())); } }); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); JFrame frame = new JFrame("Simple Graph View 2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); }
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 . ja va2s. c o 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:it.iit.genomics.cru.igb.bundles.mi.view.TestJung.java
public static void main(String[] args) { Graph<MoleculeEntry, EdgeInteraction> graph = new SparseMultigraph<>(); MoleculeEntry v1 = new MoleculeEntry("A"); v1.addGeneName("A"); v1.setTaxid("9606"); MoleculeEntry v2 = new MoleculeEntry("B"); v2.addGeneName("b"); v2.setTaxid("9606"); MoleculeEntry v3 = new MoleculeEntry("DNA"); v3.addGeneName("DNA"); v3.setTaxid(MoleculeEntry.TAXID_DNA); EdgeInteraction edge = new EdgeInteraction(true, true, true, "e1"); graph.addEdge(edge, v1, v2, EdgeType.UNDIRECTED); EdgeInteraction edge2 = new EdgeInteraction(false, false, true, "e2"); graph.addEdge(edge2, v1, v3, EdgeType.UNDIRECTED); EdgeInteraction edge3 = new EdgeInteraction(false, false, false, "e3"); graph.addEdge(edge3, v2, v3, EdgeType.UNDIRECTED); // The Layout<V, E> is parameterized by the vertex and edge types Layout<MoleculeEntry, EdgeInteraction> layout = new ISOMLayout(graph); layout.setSize(new Dimension(500, 600)); // sets the initial size of the space // The BasicVisualizationServer<V,E> is parameterized by the edge types VisualizationViewer<MoleculeEntry, EdgeInteraction> vv = new VisualizationViewer<>(layout); vv.setPreferredSize(new Dimension(550, 650)); //Sets the viewing area size vv.setBackground(Color.WHITE); Transformer<MoleculeEntry, Paint> vertexPaint = new Transformer<MoleculeEntry, Paint>() { @Override/*from w w w . j a v a 2 s. c o m*/ public Paint transform(MoleculeEntry molecule) { switch (molecule.getTaxid()) { case MoleculeEntry.TAXID_DNA: ; case MoleculeEntry.TAXID_RNA: return Color.GREEN; case MoleculeEntry.TAXID_LIGAND: return Color.MAGENTA; default: return Color.GREEN; } } }; Transformer<EdgeInteraction, Paint> edgePaint = new Transformer<EdgeInteraction, Paint>() { @Override public Paint transform(EdgeInteraction interaction) { return interaction.hasStructure ? Color.BLACK : Color.GRAY; } }; final Stroke edgeStroke01 = new BasicStroke(); final float nodeSize = 20; final Stroke edgeStrokeBothContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, true); final Stroke edgeStrokeStartContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, false); final Stroke edgeStrokeEndContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, false, true); final Stroke edgeStrokeBothContact = new CompoundStroke(edgeStroke01, edgeStrokeBothContacts, CompoundStroke.ADD); final Stroke edgeStrokeStartContact = new CompoundStroke(edgeStroke01, edgeStrokeStartContacts, CompoundStroke.ADD); final Stroke edgeStrokeEndContact = new CompoundStroke(edgeStroke01, edgeStrokeEndContacts, CompoundStroke.ADD); Transformer<EdgeInteraction, Stroke> edgeStrokeTransformer = new Transformer<EdgeInteraction, Stroke>() { @Override public Stroke transform(EdgeInteraction s) { if (s.hasContactsA && s.hasContactsB) { return edgeStrokeBothContact; } if (s.hasContactsA) { return edgeStrokeStartContact; } if (s.hasContactsB) { return edgeStrokeEndContact; } return edgeStroke01; } }; Transformer<MoleculeEntry, String> moleculeLabeller = new Transformer<MoleculeEntry, String>() { @Override public String transform(MoleculeEntry s) { return s.getGeneName(); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); vv.getRenderContext().setVertexLabelTransformer(moleculeLabeller); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); JFrame frame = new JFrame("Network " + "A"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); }
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"); }//w w w .ja v a2 s . c om }); 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); }