Java Image .setAccelerationPriority (float priority)

Syntax

Image.setAccelerationPriority(float priority) has the following syntax.

public void setAccelerationPriority(float priority)

Example

In the following code shows how to use Image.setAccelerationPriority(float priority) method.


//  www  .  j  a  va  2 s . c o  m

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageProducer;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JFrame implements ActionListener {
  Image img;

  JButton getPictureButton  = new JButton("Get Picture");

  public static void main(String[] args) {
    new Main();
  }

  public Main() {
    this.setSize(300, 300);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel picPanel = new PicturePanel();
    this.add(picPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    getPictureButton.addActionListener(this);
    buttonPanel.add(getPictureButton);
    this.add(buttonPanel, BorderLayout.SOUTH);

    this.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    String file = "a.png";
    if (file != null) {
      Toolkit kit = Toolkit.getDefaultToolkit();
      img = kit.getImage(file);
      img = img.getScaledInstance(300, -1, Image.SCALE_SMOOTH);
      img.setAccelerationPriority(0.5F);
      System.out.println(img.getAccelerationPriority());
      
      this.repaint();
    }
  }
  class PicturePanel extends JPanel {
    public void paint(Graphics g) {
      g.drawImage(img, 0, 0, this);
    }
  }

}




















Home »
  Java Tutorial »
    java.awt »




BasicStroke
BorderLayout
CardLayout
Color
Cursor
Desktop
DesktopManager
DisplayMode
EventQueue
FlowLayout
FocusTraversalPolicy
Font
FontMetrics
GradientPaint
Graphics
Graphics2D
GraphicsConfiguration
GraphicsDevice
GraphicsEnvironment
GridBagConstraints
GridBagLayout
GridLayout
Image
ItemSelectable
KeyboardFocusManager
LayoutManager
LayoutManager2
Point
Rectangle
Robot
Shape
SplashScreen
SystemColor
SystemTray
TexturePaint
TrayIcon
Toolkit
Transparency