📄 canvas.java
字号:
package panel;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class canvas extends Panel implements MouseListener,MouseMotionListener,MouseWheelListener
{
Toolkit tool;
Image img;
static int width,height,x,y,x1,y1;
Canvas cnv=new Canvas();
Dimension s;
public canvas()
{
tool=getToolkit();
s=tool.getScreenSize();
setBounds(0,0,s.width,s.height);
img=tool.getImage("Winter.jpg");
add(new JScrollPane(cnv));
width=800;
height=600;
x=0;
y=0;
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.addMouseWheelListener(this);
}
public void paint(Graphics g)
{
g.drawImage(img,x,y,width,height,cnv);
}
public void mousePressed(MouseEvent e)
{
x1=(int)e.getX()-x;
y1=(int)e.getY()-y;
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{ x=x-4;
y=y-3;
width=width+8;
height=height+6;
repaint();
}
else if (e.getModifiers()==InputEvent.BUTTON3_MASK)
{
x=x+5;
y=y+3;
width=width-8;
height=height-6;
repaint();
}
}
public void mouseDragged(MouseEvent e)
{
x=(int)e.getX()-x1;
y=(int)e.getY()-y1;
repaint();
}
public void mouseMoved(MouseEvent e)
{
}
public void mouseWheelMoved(MouseWheelEvent e)
{
int i=e.getWheelRotation();
x=x+5*i;
y=y+3*i;
width=width-8*i;
height=height-6*i;
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -