List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:com.imag.nespros.network.devices.UtilityDevice.java
public UtilityDevice(String name) { super(name);/*from w w w . j a v a2s . c o m*/ this.setCpuSpeed(500); this.setTotalMemory(10); this.setDeviceType(DeviceType.UTILITY); this.setDeviceName(name); try { byte[] imageInByte; imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/utility.jpg")); icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage()); } catch (IOException ex) { Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public Main() { try {//from w ww .j a v a 2s . c om robot = new Robot(); } catch (Exception e1) { e1.printStackTrace(); } timer = new Timer(3000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); Image image = robot.createScreenCapture(size); label.setIcon(new ImageIcon(image)); frame.setVisible(true); } }); timer.setRepeats(false); button.addActionListener(e -> { frame.setVisible(false); timer.start(); }); frame.add(button, BorderLayout.NORTH); frame.add(label, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 768); frame.setVisible(true); }
From source file:org.martus.client.swingui.dialogs.UiChartPreviewDlg.java
public static JLabel createChartComponent(JFreeChart chart) { BufferedImage image = chart.createBufferedImage(800, 600); ImageIcon imageIcon = new ImageIcon(image); JLabel label = new JLabel(imageIcon); return label; }
From source file:Main.java
public Main() { Image grass = createImage(Color.green); Image water = createImage(Color.blue); grassIcon = new ImageIcon(grass); waterIcon = new ImageIcon(water); setLayout(new GridLayout(labelGrid.length, labelGrid[0].length)); for (int row = 0; row < labelGrid.length; row++) { for (int col = 0; col < labelGrid[row].length; col++) { ImageIcon icon = MAP_1_ST[row].charAt(col) == '0' ? grassIcon : waterIcon; labelGrid[row][col] = new JLabel(icon); add(labelGrid[row][col]);/* w ww.jav a 2 s . co m*/ } } }
From source file:Main.java
ScreenCaptureRectangle(final BufferedImage screen) { BufferedImage screenCopy = new BufferedImage(screen.getWidth(), screen.getHeight(), screen.getType()); JLabel screenLabel = new JLabel(new ImageIcon(screenCopy)); JScrollPane screenScroll = new JScrollPane(screenLabel); screenScroll.setPreferredSize(new Dimension(300, 300)); repaint(screen, screenCopy);// w w w. j a va2 s . c om screenLabel.repaint(); screenLabel.addMouseMotionListener(new MouseMotionAdapter() { Point start = new Point(); @Override public void mouseMoved(MouseEvent me) { start = me.getPoint(); repaint(screen, screenCopy); screenLabel.repaint(); } @Override public void mouseDragged(MouseEvent me) { Point end = me.getPoint(); captureRect = new Rectangle(start, new Dimension(end.x - start.x, end.y - start.y)); repaint(screen, screenCopy); screenLabel.repaint(); } }); JOptionPane.showMessageDialog(null, screenScroll); }
From source file:Main.java
public LoadImage() { super(new GridLayout()); try {// w w w . j a v a 2s .c o m image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); } catch (Exception ex) { ex.printStackTrace(System.err); } int w = image.getWidth(null) / 2; int h = image.getHeight(null) / 2; this.add(new JLabel(new ImageIcon(image.getScaledInstance(w, h, Image.SCALE_SMOOTH)))); }
From source file:com.uksf.mf.core.utility.loaders.ImageLoad.java
/** * Loads images from resources/*from w ww. j a va 2 s. co m*/ * @throws IOException file read error */ public void loadImages() throws IOException { LogHandler.logNoTime(HASHSPACE); LogHandler.logSeverity(INFO, "Loading images"); LOGO_LIGHT_16 = new ImageIcon(toByteArray(getClass().getResourceAsStream(LOGOS + "light16.png"))); LOGO_LIGHT_32 = new ImageIcon(toByteArray(getClass().getResourceAsStream(LOGOS + "light32.png"))); LOGO_LIGHT_64 = new ImageIcon(toByteArray(getClass().getResourceAsStream(LOGOS + "light64.png"))); LOGO_64 = new ImageIcon(toByteArray(getClass().getResourceAsStream(LOGOS + "uksf64.png"))); ICON_HOME = new ImageIcon(toByteArray(getClass().getResourceAsStream(ICONS + "home.png"))); ICON_HOME_HOVER = changeImageColour(ICON_HOME, COLOUR_FOREGROUND_DARK.getRGB()); ICON_CLOSE = new ImageIcon(toByteArray(getClass().getResourceAsStream(ICONS + "close.png"))); ICON_CLOSE_HOVER = changeImageColour(ICON_CLOSE, COLOUR_FOREGROUND_DARK.getRGB()); ICON_INFO = new ImageIcon(toByteArray(getClass().getResourceAsStream(ICONS + "info.png"))); ICON_INFO_HOVER = changeImageColour(ICON_INFO, COLOUR_FOREGROUND_DARK.getRGB()); FEELSBADMAN = new ImageIcon(toByteArray(getClass().getResourceAsStream(ICONS + "fbm64.png"))); LogHandler.logSeverity(INFO, "Images loaded"); }
From source file:MainClass.java
private void makeGUI() { setLayout(new FlowLayout()); ImageIcon france = new ImageIcon("france.gif"); JButton jb = new JButton(france); jb.setActionCommand("France"); jb.addActionListener(this); add(jb);/*ww w . ja v a2 s . c om*/ ImageIcon germany = new ImageIcon("germany.gif"); jb = new JButton(germany); jb.setActionCommand("Germany"); jb.addActionListener(this); add(jb); ImageIcon italy = new ImageIcon("italy.gif"); jb = new JButton(italy); jb.setActionCommand("Italy"); jb.addActionListener(this); add(jb); ImageIcon japan = new ImageIcon("japan.gif"); jb = new JButton(japan); jb.setActionCommand("Japan"); jb.addActionListener(this); add(jb); jtf = new JTextField(15); add(jtf); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }/* ww w .ja v a2 s . c om*/ }; JMenuItem item; popup.add(item = new JMenuItem("Left")); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:MainClass.java
public MyCanvas() { try {//from ww w. jav a2s.co m InputStream in = getClass().getResourceAsStream("myExampleImage.jpg"); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); mImage = decoder.decodeAsBufferedImage(); in.close(); } catch (Exception e) { System.err.println(e.getLocalizedMessage()); } ImageIcon icon = new ImageIcon(mImage); add(new JLabel(icon)); }