各位高手,我做了一个界面,现在想实现图片放大功能,即按放大按钮后,鼠标变成放大图标形,点击图片时,以此点为中心实现图片放大功能,谢谢啦!
------解决方案--------------------
看看这个,也许就会了:
- Java code
import java.awt.Graphics;import java.awt.Image;import java.awt.Toolkit;import javax.swing.JFrame;import javax.swing.JPanel;public class TryImageI extends JFrame{ public JPanel jp=new JPanel(){ Image img=Toolkit.getDefaultToolkit().getImage("image/2.jpg"); Image img1=img.getScaledInstance(141, 102, Image.SCALE_SMOOTH); Image img2=img.getScaledInstance(70, 53, Image.SCALE_SMOOTH); public void paint(Graphics g){ g.drawImage(img,10,10,this); g.drawImage(img1, 300,10,this ); g.drawImage(img2, 460, 10,this); } }; public TryImageI(){ this.add(jp); this.setTitle("图像缩放演示"); this.setBounds(100,100,550,260); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[]args){ new TryImageI(); }}