List of usage examples for java.awt Color Color
public Color(ColorSpace cspace, float[] components, float alpha)
From source file:Main.java
public static void main(String[] args) { Color TRUE_COLOR = new Color(180, 200, 255); Color FALSE_COLOR = new Color(255, 100, 100); final MyBean panel = new MyBean(); panel.setTitle(true);/*from w w w. j a va2 s . co m*/ panel.setBackground(TRUE_COLOR); panel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { panel.setTitle(!panel.getTitle()); } }); panel.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(MyBean.TITLE_PROP_NAME)) { panel.setBackground(panel.getTitle() ? TRUE_COLOR : FALSE_COLOR); } } }); JFrame frame = new JFrame(); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { byte ff = (byte) 0xff; byte[] r = { ff, 0, 0, ff, 0 }; byte[] g = { 0, ff, 0, ff, 0 }; byte[] b = { 0, 0, ff, ff, 0 }; ColorModel cm = new IndexColorModel(3, 5, r, g, b); Color[] colors = { new Color(255, 0, 0), new Color(0, 255, 0), new Color(0, 0, 255) }; for (int i = 0; i < colors.length; i++) { int rgb = colors[i].getRGB(); Object pixel = cm.getDataElements(rgb, null); System.out.println(colors[i] + " -> " + ((byte[]) pixel)[0]); }//from w w w.j a va2s.c o m for (byte i = 0; i < 5; i++) { int[] unnormalizedComponents = cm.getComponents(i, null, 0); System.out.print(i + " -> unnormalized components"); for (int j = 0; j < unnormalizedComponents.length; j++) System.out.print(" " + unnormalizedComponents[j]); System.out.println(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_USHORT_GRAY); Graphics2D g2d = bi.createGraphics(); g2d.setColor(Color.WHITE);//from w ww .j av a2s .c om g2d.fillRect(0, 0, 100, 100); g2d.setColor(new Color(255, 123, 0)); g2d.drawLine(100, 100, 1, 1); g2d.dispose(); BufferedImage scaledImage = new BufferedImage(1000, 1000, BufferedImage.TYPE_USHORT_GRAY); Graphics2D graphics2D = scaledImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(bi, 0, 0, 1000, 1000, null); graphics2D.dispose(); ImageIO.write(scaledImage, "png", new File("c:/Java_Dev/Test.png")); bi.flush(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();/*from w ww . j av a 2s . co m*/ Chunk c; c = new Chunk("Quick brown fox jumps over the lazy dog."); c.setUnderline(new Color(0xFF, 0x00, 0x00), 0.0f, 0.3f, 0.0f, 0.4f, PdfContentByte.LINE_CAP_ROUND); document.add(c); document.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from w w w . ja va2s .c om Chunk c; c = new Chunk("Quick brown fox jumps over the lazy dog."); c.setUnderline(new Color(0x00, 0xFF, 0x00), 5.0f, 0.0f, 0.0f, -0.5f, PdfContentByte.LINE_CAP_PROJECTING_SQUARE); document.add(c); document.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();//from ww w . ja v a 2 s . c o m Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0xFF, 0xFF, 0xFF)); Chunk fox = new Chunk("this is a", font); fox.setBackground(new Color(0xa5, 0x2a, 0x2a)); Phrase p = new Phrase(fox); p.add(" test"); Chunk dog = new Chunk(" another test", new Font(Font.TIMES_ROMAN, 14, Font.ITALIC)); dog.setBackground(new Color(0xFF, 0x00, 0x00), 10, -30, 20, -10); p.add(dog); document.add(p); document.close(); }
From source file:ComponentTest.java
public static void main(String[] args) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();// w w w. j a v a 2 s .c o m int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0); float[] components = fifty.getComponents(null); System.out.print("Original normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); System.out.println();/* ww w . ja v a 2 s .c o m*/ int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0); System.out.print("Original unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); Object pixel = cm.getDataElements(unnormalized, 0, (Object) null); System.out.print("Pixel samples: "); byte[] pixelBytes = (byte[]) pixel; for (int i = 0; i < 3; i++) System.out.print(pixelBytes[i] + " "); System.out.println(); unnormalized = cm.getComponents(pixel, null, 0); System.out.print("Derived unnormalized components: "); for (int i = 0; i < 3; i++) System.out.print(unnormalized[i] + " "); System.out.println(); components = cm.getNormalizedComponents(unnormalized, 0, null, 0); System.out.print("Derived normalized components: "); for (int i = 0; i < 3; i++) System.out.print(components[i] + " "); }
From source file:MyLabel.java
public static void main(String[] args) { String lyrics = "<html>Line<br>line<br>line</html>"; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); JLabel label = new JLabel(lyrics); label.setFont(new Font("Georgia", Font.PLAIN, 14)); label.setForeground(new Color(50, 50, 25)); panel.add(label, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JFrame f = new JFrame(); f.add(panel);//from ww w . j ava 2s . c om f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:LINECAPROUNDPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*ww w.ja va 2 s. c om*/ PdfWriter.getInstance(document, new FileOutputStream("LINECAPROUNDPDF.pdf")); document.open(); Chunk chunk; chunk = new Chunk("Multiple lines"); chunk.setUnderline(new Color(0xFF, 0x00, 0x00), 0.0f, 0.3f, 0.0f, 0.4f, PdfContentByte.LINE_CAP_ROUND); document.add(chunk); } catch (Exception ioe) { System.err.println(ioe.getMessage()); } document.close(); }