List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Main.java
public static void main(String[] args) { String imageFile = "A.jpg"; RepaintManager.currentManager(null).setDoubleBufferingEnabled(false); Image image = Toolkit.getDefaultToolkit().getImage(Main.class.getResource(imageFile)); image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_AREA_AVERAGING); JFrame frame = new JFrame("DragImage"); frame.getContentPane().add(new Main(image)); frame.setSize(300, 300);//w w w .j a v a2 s . c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Toolkit tk = Toolkit.getDefaultToolkit(); final Main main = new Main(); tk.addAWTEventListener(main, AWTEvent.WINDOW_EVENT_MASK); final JFrame frame = new JFrame(""); frame.setName("your frame"); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Quit") { public void actionPerformed(ActionEvent evt) { try { main.saveSettings();//from ww w . j a va2 s. c o m System.exit(0); } catch (Exception ex) { System.out.println(ex); } } }); mb.add(menu); frame.setJMenuBar(mb); frame.pack(); frame.setVisible(true); }
From source file:DragImage.java
public static void main(String[] args) { String imageFile = "A.jpg"; // Turn off double buffering RepaintManager.currentManager(null).setDoubleBufferingEnabled(false); Image image = Toolkit.getDefaultToolkit().getImage(DragImage.class.getResource(imageFile)); image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT); JFrame frame = new JFrame("DragImage"); frame.getContentPane().add(new DragImage(image)); frame.setSize(300, 300);/*from w w w. java2 s. com*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { ImageObserver myObserver = new ImageObserver() { public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) { if ((flags & HEIGHT) != 0) System.out.println("Image height = " + height); if ((flags & WIDTH) != 0) System.out.println("Image width = " + width); if ((flags & FRAMEBITS) != 0) System.out.println("Another frame finished."); if ((flags & SOMEBITS) != 0) System.out.println("Image section :" + new Rectangle(x, y, width, height)); if ((flags & ALLBITS) != 0) System.out.println("Image finished!"); if ((flags & ABORT) != 0) System.out.println("Image load aborted..."); return true; }/*from w ww.j a v a 2s .c o m*/ }; Toolkit toolkit = Toolkit.getDefaultToolkit(); Image img = toolkit.getImage(args[0]); toolkit.prepareImage(img, -1, -1, myObserver); }
From source file:ActiveTray.java
public static void main(String args[]) throws Exception { if (SystemTray.isSupported() == false) { System.err.println("No system tray available"); return;/*w w w. j a v a 2s. c o m*/ } final SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener propListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { TrayIcon oldTray[] = (TrayIcon[]) evt.getOldValue(); TrayIcon newTray[] = (TrayIcon[]) evt.getNewValue(); System.out.println(oldTray.length + " / " + newTray.length); } }; tray.addPropertyChangeListener("trayIcons", propListener); Image image = Toolkit.getDefaultToolkit().getImage("jpgIcon.jpg"); PopupMenu popup = new PopupMenu(); MenuItem item = new MenuItem("Hello, World"); final TrayIcon trayIcon = new TrayIcon(image, "Tip Text", popup); ActionListener menuActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("Good-bye", "Cruel World", TrayIcon.MessageType.WARNING); } }; item.addActionListener(menuActionListener); popup.add(item); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); } }; trayIcon.addActionListener(actionListener); tray.add(trayIcon); }
From source file:kcse_2013_results.BarChartExample.java
public static void main(String[] args) { // Create a simple Bar chart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(6, "Profit", "Jane"); dataset.setValue(7, "Profit", "Tom"); dataset.setValue(8, "Profit", "Jill"); dataset.setValue(5, "Profit", "John"); dataset.setValue(12, "Profit", "Fred"); JFreeChart chart = ChartFactory.createBarChart("Comparison between Salesman", "Salesman", "Profit", dataset, PlotOrientation.VERTICAL, false, true, false); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final int width = screenSize.width; final int height = screenSize.height; try {//www . j a v a 2s . c o m ChartUtilities.saveChartAsJPEG(new File("C:\\Users\\Wachira\\Desktop\\chart.jpg"), chart, width, height); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:ClippedDragImage.java
public static void main(String[] args) { String imageFile = "A.jpg"; Image image = Toolkit.getDefaultToolkit().getImage(ClippedDragImage.class.getResource(imageFile)); image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT); JFrame frame = new JFrame("ClippedDragImage"); frame.getContentPane().add(new ClippedDragImage(image)); frame.setSize(300, 300);//from w w w. java2s .c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table images (Id int, b BLOB);"); File file = new File("myimage.gif"); FileInputStream fis = new FileInputStream(file); PreparedStatement ps = conn.prepareStatement("insert into images values (?,?)"); ps.setString(1, "10"); ps.setBinaryStream(2, fis);/*from w w w . j a v a2 s . c o m*/ ps.executeUpdate(); ResultSet rset = st.executeQuery("select b from images"); InputStream stream = rset.getBinaryStream(1); ByteArrayOutputStream output = new ByteArrayOutputStream(); int a1 = stream.read(); while (a1 >= 0) { output.write((char) a1); a1 = stream.read(); } Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray()); output.close(); ps.close(); fis.close(); st.close(); conn.close(); }
From source file:IconPaint.java
public static void main(String[] args) { Image starImage = Toolkit.getDefaultToolkit().getImage(IconPaint.iconFile); IconPanel starPanel = new IconPanel(starImage); JFrame f = new JFrame("Icon"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//w w w .j a v a 2s.c o m } }); f.getContentPane().add(starPanel, BorderLayout.CENTER); f.setSize(new Dimension(550, 200)); f.setVisible(true); }
From source file:SystemTrayTest.java
public static void main(String[] args) { final TrayIcon trayIcon; if (!SystemTray.isSupported()) { System.err.println("System tray is not supported."); return;/*from w ww . j a va 2 s . co m*/ } SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().getImage("cookie.png"); PopupMenu popup = new PopupMenu(); MenuItem exitItem = new MenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); popup.add(exitItem); trayIcon = new TrayIcon(image, "Your Fortune", popup); trayIcon.setImageAutoSize(true); trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("How do I turn this off?", "Right-click on the fortune cookie and select Exit.", TrayIcon.MessageType.INFO); } }); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); return; } final List<String> fortunes = readFortunes(); Timer timer = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent e) { int index = (int) (fortunes.size() * Math.random()); trayIcon.displayMessage("Your Fortune", fortunes.get(index), TrayIcon.MessageType.INFO); } }); timer.start(); }