public static class TransformingCanvas extends JComponent {
public static final long serialVersionUID = 1L;
public double translateX;
public double translateY;
public double scale;
@SuppressWarnings("unused")
private ImageProvider imageProvider;
TransformingCanvas() {
translateX = 0;
translateY = 0;
scale = 0.5;
setOpaque(true);
setDoubleBuffered(true);
}
public void setImageProvider(ImageProvider imageProvider) {
this.imageProvider = imageProvider;
repaint();
}
@SuppressWarnings("unchecked")
@Override
public void paint(Graphics g) {
Image image = ImageProvider.getImage();
AffineTransform tx = new AffineTransform();
tx.translate(translateX, translateY);
tx.scale(scale, scale);
Graphics2D ourGraphics = (Graphics2D) g;
ourGraphics.setColor(Color.WHITE);
ourGraphics.fillRect(0, 0, getWidth(), getHeight());
ourGraphics.setTransform(tx);
ourGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
ourGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
ourGraphics.drawImage(image, 100, 100, this);
}
}
public class tests {
public static TransformingCanvas canvas;
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel toolbar = new JPanel();
final String[] number = new String[] {"", "1044", "1045", "1046", "1054"};
final JComboBox combo = new JComboBox(number);
combo.setSelectedIndex(0);
combo.setEditable(true);
final JButton butGo = new JButton("GO");
butGo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas.setImageProvider(new ImageProvider() {
public Image getImage() {
Object n = combo.getSelectedItem();
Image image = new ImageIcon(n + ".jpg").getImage();
return image;
}
});
}
});
toolbar.add(combo);
toolbar.add(butGo);
public static class TransformingCanvas extends JComponent {
public static final long serialVersionUID = 1L;
public double translateX;
public double translateY;
public double scale;
private ImageProvider imageProvider;
TransformingCanvas() {
translateX = 0;
translateY = 0;
scale = 0.5;
setOpaque(true);
setDoubleBuffered(true);
}
public void setImageProvider(ImageProvider imageProvider) {
this.imageProvider = imageProvider;
repaint();
}
@SuppressWarnings("unchecked")
@Override
public void paint(Graphics g) {
AffineTransform tx = new AffineTransform();
tx.translate(translateX, translateY);
tx.scale(scale, scale);
Graphics2D ourGraphics = (Graphics2D) g;
ourGraphics.setColor(Color.WHITE);
ourGraphics.fillRect(0, 0, getWidth(), getHeight());
ourGraphics.setTransform(tx);
ourGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
ourGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
ourGraphics.drawImage((Image) imageProvider, 100, 100, this);
}
}
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Я так понял выделеноой яве, памяти не хватает?
Как то можно сделать, чтобы каждый раз подгружая новую картинку, память очищалась или что-то в этом роде?