AWT / CATATAN</>↗AWT04 Feb 2008
In this example you’ll see how to create a screen capture / screenshot and save it as an image file such a PNG image. Some classes are use in this program including the java.awt.Robot, java.awt.image.BufferedImage and javax.imageio.ImageIO. package org.kodejava.awt; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.awt.AWTException; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.io.File; import java.io.IOE...
AWT / CATATAN</>↗AWT20 Jan 2007
package org.kodejava.awt; import java.awt.GraphicsEnvironment; public class FontFamilyNameList { public static void main(String[] args) { // Get all available font family names from GraphicsEnvironment GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] familyNames = ge.getAvailableFontFamilyNames(); // Iterates familyNames array to display the available font's family names for (String familyName : familyNames) { System.out.println("Family nam...
AWT / CATATAN</>↗AWT16 Jan 2007
package org.kodejava.awt; import java.awt.Font; import java.awt.GraphicsEnvironment; public class FontNameList { public static void main(String[] args) { // Get all available fonts from GraphicsEnvironment GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); // Iterates all available fonts and get their name and family name for (Font font : fonts) { String fontName = font.getName(); String familyName […]
AWT / CATATAN</>↗AWT18 Jul 2006
package org.kodejava.awt; import java.awt.*; public class ScreenSizeExample { public static void main(String[] args) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); System.out.println("Screen Width: " + screenSize.getWidth()); System.out.println("Screen Height: " + screenSize.getHeight()); } } The output of the code snippet above: Screen Width: 2560.0 Screen Height: 1080.0
AWT / CATATAN</>↗AWT10 Jun 2006
Here you see a code sample to read an image file. This code will work either the image file is located in a file folder or inside a jar file. You can use javax.imageio.ImageIO class to read the image file. package org.kodejava.awt; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; public class ReadingImage { public […]
AWT / CATATAN</>↗AWT11 Apr 2006
package org.kodejava.awt; import java.awt.*; public class BeepExample { public static void main(String[] args) { // This is the way we can send a beep audio out. Toolkit.getDefaultToolkit().beep(); } } Using Runtime.exec() method we can do something like the code snippet below to produce beep sound using powershell command. try { Process process = Runtime.getRuntime().exec( new […]