Awt etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Awt etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

2 Aralık 2022 Cuma

Awt ComponentColorModel Sınıfı

Giriş
Şu satırı dahil ederiz
import java.awt.image.ComponentColorModel;
ColorModel sınıfı pixel verisini RGB'ye çevirir. Yani pixel başına kullanılacak renk uzayı, alfa kanalı bilgilerinin nasıl okunup yazılacağını bilir. Kalıtım şöyle
ColorModel
  ComponentColorModel
  IndexColorModel
  PackedColorModel <-- soyut sınıf
    DirectColorModel
constructor
Şöyle yaparız
ComponentColorModel cm = new ComponentColorModel(
  ColorSpace.getInstance(ColorSpace.CS_sRGB),
  false,                  //no alpha channel
  false,                  //not premultiplied
  ColorModel.OPAQUE,
  DataBuffer.TYPE_BYTE); //important - data in the buffer is saved by the byte

22 Ocak 2021 Cuma

Awt SystemTray Sınıfı

Giriş
Şu satırı dahil ederiz
import java.awt.SystemTray;
displayMessage metodu
Şöyle yaparız
String toolTip = "...";

if (SystemTray.isSupported()) {
  SystemTray tray = SystemTray.getSystemTray();
  TrayIcon[] trayIcons = tray.getTrayIcons();

  for (TrayIcon trayIcon: trayIcons ) {
    if (trayIcon.getToolTip().equals(toolTip)) {
      tray.remove(trayIcon);
    }
  }

  //If the icon is a file : e.g src/main/resources/2_1.jpg
  Image image = Toolkit.getDefaultToolkit().createImage("2_1.jpg");
  //Alternative (if the icon is on the classpath):
  //Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));

  TrayIcon trayIcon = new TrayIcon(image, toolTip);
  //Let the system resize the image if needed
  trayIcon.setImageAutoSize(true);
  //Set tooltip text for the tray icon
  tray.add(trayIcon);

  trayIcon.displayMessage("...", TrayIcon.MessageType.INFO);
}

17 Ocak 2020 Cuma

Awt Robot Sınıfı

Giriş
Şöyle yaparız.
import java.awt.Robot;
constructor
Şöyle yaparız.
Robot r= new Robo t();
createScreenCapture metodu
Örnek - AWT Bileşeni
Şöyle yaparız. Esas kod burada.
public static BufferedImage createImage(Component component)
  throws AWTException {

  Point p = new Point(0, 0);

  SwingUtilities.convertPointToScreen(p, component);

  Rectangle region = component.getBounds();
  region.x = p.x;
  region.y = p.y;

  BufferedImage bufferedImage = new Robot().createScreenCapture(rectangle);
  return bufferedImage;

}
Örnek - Tüm Ekran
Şöyle yaparız
try {
  Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  BufferedImage  capture = new Robot().createScreenCapture(screenRect);
  ImageIO.write(capture, "JPEG", new File("printed1.jpg"));
} catch (Exception e) {
  e.printStackTrace();
}
delay metodu
Şöyle yaparız.
r.delay (500);
getPixelColor metodu
Şöyle yaparız.
Rectangle screenRect = new Rectangle (700, 50, 530, 950);

float[] color = new float[3];
r.getPixelColor (755, 800).getRGBColorComponents (color);
keyPress metodu
Şöyle yaparız.
r.keyPress (20);
keyRelease metodu
Şöyle yaparız.
r.keyRelease (20);
mouseMove metodu
Şöyle yaparız.
r.mouseMove (755, 850);
mousePress metodu
Şöyle yaparız.
r.mousePress (InputEvent.BUTTON1_DOWN_MASK);
mouseRelease metodu
Şöyle yaparız.
r.mousePress (InputEvent.BUTTON1_DOWN_MASK);
Thread.sleep (100L);
r.mouseRelease (InputEvent.BUTTON1_DOWN_MASK);

15 Ocak 2020 Çarşamba

Awt Color Sınıfı

cosntructor - int
32 bit'in sadece ilk 24 bitini kullanır.
Örnek
Şöyle yaparız. Bu koddatoplam 28 bit çarpım yapılıyor.  6 tane 0 sıfır var.
new Color((int)(Math.random() * 0x1000000))

getHSBColor metodu
Örnek ver

12 Ocak 2020 Pazar

Awt Component Sınıfı

Giriş
Bu nesneyi dinleyen Listener'ları silmeye gerek yok. Açıklaması şöyle
Generally speaking, removing listeners is unnecessary. Listeners are garbage collected when a control is disposed of, provided that there are no other references to the listener in the application program.
addMouseListener metodu
MouseListener arayüzü alır.

Örnek
Şöyle yaparız.
MouseListener ml = new MouseAdapter() {
  public void mouseClicked(java.awt.event.MouseEvent evt) {
    chatInputMouseClicked(evt);
  }
};
chatInput.addMouseListener (ml);
...
chatInput.removeMouseListener (ml);
getListeners metodu
İmzası şöyle.
public EventListener[] getListeners(Class listenerType)
getMouseListeners
İmzası şöyle.
public MouseListener[] getMouseListeners();

9 Ocak 2020 Perşembe

Awt Clipboard Sınıfı

Kullanım
getContents() metodu ile Transferrable nesnesi elde edilir. Bu nesne üzerinde işlem yapılır.
getData() metodu ile veri istenilen formatta okunur. Hata olursa exception fırlatır.
setContents() metodu ile veri yazılır.

constructor
Şöyle yaparız.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
addFlavorListener metodu
Şu satırı dahil ederiz.
import java.awt.datatransfer.FlavorEvent;
import java.awt.datatransfer.FlavorListener;
Şöyle yaparız.
clipboard().addFlavorListener(new FlavorListener() { 
  @Override 
  public void flavorsChanged(FlavorEvent e) {
    System.out.println("ClipBoard UPDATED: " + e.getSource() + " " + e.toString());
  } 
}); 
getContents metodu
Transferrable nesnesi döner. Metoda geçilen requestor parametresi kullanılmaz. null geçilebilir.

Örnek
Şöyle yaparız.
Transferable trans = clipboard.getContents(this);  
Örnek
Şöyle yaparız.
Transferable t = clipboard.getContents(null);


try {
  if ( t.isDataFlavorSupported(DataFlavor.stringFlavor) ) {
    String data = (String)t.getTransferData( DataFlavor.stringFlavor );
    System.out.println( "Clipboard contents: " + data );
  }           
} catch (Exception e) {
  ...
}
getData metodu
Örnek - String okuma
Şöyle yaparız.
String str;
try {
  str = (String) clipboard.getData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException ex) {
  ...
}
setContents metodu
Örnek - String yazma
Şöyle yaparız.
StringSelection selection = new StringSelection("A");       
clipboard.setContents(selection, null);
Örnek
ClipboardOwner olarak kendi sınıfımızı vermek için şöyle yaparız.
clipboard.setContents(clipboard.getContents(null), this);