php滑动拼图片验证

1、获取代码包

https://github.com/GeeTeam/gt-php-sdk 
2、客户端SDK

http://www.geetest.com/install/sections/idx-client-sdk.html 
3、效果

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实现滑动图片拼图验证的步骤如下: 1.准备两张图片,一张是完整的原图,另一张是被拆分的拼图。 2.使用Java的Graphics类将原图和拼图绘制到JPanel上。 3.使用Java的Random类生成一个随机位置,将拼图绘制到原图的随机位置。 4.使用Java的MouseAdapter类监听鼠标事件,当用户按下鼠标并拖动时,将拼图跟随鼠标移动。 5.使用Java的Rectangle类判断拼图是否在原图的正确位置,如果是,则验证通过,否则提示用户重新拼图。 下面是一个简单的Java代码示例: ```java import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Random; import javax.swing.*; public class SlidePuzzle extends JPanel { private Image img; // 原图 private Image puzzleImg; // 拼图 private Point puzzleLoc; // 拼图位置 private Rectangle puzzleRect; // 拼图矩形 private boolean isDragging; // 是否正在拖动 public SlidePuzzle() { // 加载图片 img = new ImageIcon("original.jpg").getImage(); puzzleImg = new ImageIcon("puzzle.jpg").getImage(); // 随机生成拼图位置 Random rand = new Random(); int x = rand.nextInt(img.getWidth(null) - puzzleImg.getWidth(null)); int y = rand.nextInt(img.getHeight(null) - puzzleImg.getHeight(null)); puzzleLoc = new Point(x, y); // 创建拼图矩形 puzzleRect = new Rectangle(puzzleLoc.x, puzzleLoc.y, puzzleImg.getWidth(null), puzzleImg.getHeight(null)); // 添加鼠标监听器 addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (puzzleRect.contains(e.getPoint())) { isDragging = true; } } public void mouseReleased(MouseEvent e) { if (isDragging) { isDragging = false; if (puzzleRect.intersects(new Rectangle(300, 300, 100, 100))) { JOptionPane.showMessageDialog(null, "验证通过!"); } else { JOptionPane.showMessageDialog(null, "拼图不正确,请重新拼图!"); } } } }); addMouseMotionListener(new MouseAdapter() { public void mouseDragged(MouseEvent e) { if (isDragging) { puzzleLoc.translate(e.getX() - puzzleRect.x, e.getY() - puzzleRect.y); puzzleRect.setLocation(puzzleLoc); repaint(); } } }); } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img, 0, 0, null); g.drawImage(puzzleImg, puzzleLoc.x, puzzleLoc.y, null); } public static void main(String[] args) { JFrame frame = new JFrame("滑动拼图验证"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 600); frame.add(new SlidePuzzle()); frame.setVisible(true); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值