图形配对

简介: package peidui; import java.awt.event.*; import java.awt.*;    import javax.swing.*; import javax.
package  peidui;
import  java.awt.event.*;
import  java.awt.*;
  
import  javax.swing.*;
import  javax.swing.border.LineBorder;
public  class  peidui  extends  JFrame  implements  MouseMotionListener,MouseListener{
     JLabel j1,j2,j3,j4,j5,j6;
     JPanel jp1,jp2;
     Point presspoint;
     public  static  void  main(String[] args) {
         peidui pd= new  peidui();
     }
     public  peidui(){
         j1= new  JLabel( new  ImageIcon(getClass().getResource( "bike.jpg" )));
         j2= new  JLabel( new  ImageIcon(getClass().getResource( "coffe.jpg" )));
         j3= new  JLabel( new  ImageIcon(getClass().getResource( "dress.jpg" )));
         j4= new  JLabel( "咖啡" ,JLabel.CENTER);
         j5= new  JLabel( "衣服" ,JLabel.CENTER);
         j6= new  JLabel( "自行车" ,JLabel.CENTER);
         jp1= new  JPanel();
         jp2= new  JPanel();
         j1.setPreferredSize( new  Dimension(  60 60 ));
         j1.setBorder( new  LineBorder(Color.BLACK));
         j2.setPreferredSize( new  Dimension(  60 60 ));
         j2.setBorder( new  LineBorder(Color.BLACK));
         j3.setPreferredSize( new  Dimension(  60 60 ));
         j3.setBorder( new  LineBorder(Color.BLACK));
         j4.setBackground(Color.green);
         j4.setOpaque( true );
         j4.setPreferredSize( new  Dimension(  80 80 ));
         j5.setBackground(Color.green);
         j5.setOpaque( true );
         j5.setPreferredSize( new  Dimension(  80 80 ));
         j6.setBackground(Color.green);
         j6.setOpaque( true );
         j6.setPreferredSize( new  Dimension(  80 80 ));
         j1.addMouseListener( this ); //注册监听
         j1.addMouseMotionListener( this ); //注册监听
         j2.addMouseListener( this );
         j2.addMouseMotionListener( this );
         j3.addMouseListener( this );
         j3.addMouseMotionListener( this );
          
         jp1.add(j1);
         jp1.add(j2);
         jp1.add(j3);
         this .setGlassPane(jp1); //加玻璃板把jp1放到玻璃板上
         this .getGlassPane().setVisible( true ); //玻璃板的显示即jp1的显示
         jp1.setOpaque( false ); //面板透明,玻璃板不透明窗体
         jp2.add(j4);
         jp2.add(j5);
         jp2.add(j6);
         this .add(jp2,BorderLayout.SOUTH);
         this .setTitle( "配对游戏" );
         this .setLocation( 500 200 );
         this .setSize( 300 300 );
         this .setVisible( true );
         this .setResizable( true );
         this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
     @Override
     public  void  mouseClicked(MouseEvent arg0) {
         // 单击
          
     }
     @Override
     public  void  mouseEntered(MouseEvent arg0) {
         // 进入
          
     }
     @Override
     public  void  mouseExited(MouseEvent arg0) {
         // 退出
          
     }
     @Override
     public  void  mousePressed(MouseEvent arg0) {
         // 一直按住
         presspoint=arg0.getPoint();
     }
     @Override
     public  void  mouseReleased(MouseEvent arg0) {
         // 释放
         if (check()){
             this .getGlassPane().setVisible( false );
             j6.setBackground(Color.red);
             j6.setText( "配对成功" );
             j5.setBackground(Color.red);
             j5.setText( "配对成功" );
             j4.setBackground(Color.red);
             j4.setText( "配对成功" );
         }
     }
     @Override
     public  void  mouseDragged(MouseEvent arg0) {
         //拖拽
         Point curentPoint=arg0.getPoint();
         JLabel imgsource=(JLabel)arg0.getSource();
         Point labPoint=imgsource.getLocation();
         imgsource.setLocation(labPoint.x+(curentPoint.x-presspoint.x), labPoint.y+(curentPoint.y-presspoint.y) );
     }
     @Override
     public  void  mouseMoved(MouseEvent arg0) {
         // 移动
          
     }
     public  boolean  check(){
         boolean  asc= true ;
         Point a=j1.getLocationOnScreen();
         Point b=j6.getLocationOnScreen();
         if (a.x<b.x||a.y<b.y||a.x>b.x+  80 ||a.y>b.y+  80 )
         {
             asc= false ;
             j6.setBackground(Color.green);
  
         }
         Point c=j3.getLocationOnScreen();
         Point d=j5.getLocationOnScreen();
         if (c.x<d.x||c.y<d.y||c.x>d.x+  80 ||c.y>d.y+  80 )
         {
             asc= false ;
             j5.setBackground(Color.green);
  
         }
         Point e=j2.getLocationOnScreen();
         Point f=j4.getLocationOnScreen();
         if (e.x<f.x||e.y<f.y||e.x>f.x+  80 ||e.y>f.y+  80 )
         {
             asc= false ;
             j4.setBackground(Color.green);
  
         }
         return  asc;
     }
  
}
相关文章
|
1天前
|
弹性计算 运维 搜索推荐
三翼鸟携手阿里云ECS g9i:智慧家庭场景的效能革命与未来生活新范式
三翼鸟是海尔智家旗下全球首个智慧家庭场景品牌,致力于提供覆盖衣、食、住、娱的一站式全场景解决方案。截至2025年,服务近1亿家庭,连接设备超5000万台。面对高并发、低延迟与稳定性挑战,全面升级为阿里云ECS g9i实例,实现连接能力提升40%、故障率下降90%、响应速度提升至120ms以内,成本降低20%,推动智慧家庭体验全面跃迁。
|
2天前
|
数据采集 人工智能 自然语言处理
3分钟采集134篇AI文章!深度解析如何通过云无影AgentBay实现25倍并发 + LlamaIndex智能推荐
结合阿里云无影 AgentBay 云端并发采集与 LlamaIndex 智能分析,3分钟高效抓取134篇 AI Agent 文章,实现 AI 推荐、智能问答与知识沉淀,打造从数据获取到价值提炼的完整闭环。
343 90
|
9天前
|
人工智能 自然语言处理 前端开发
Qoder全栈开发实战指南:开启AI驱动的下一代编程范式
Qoder是阿里巴巴于2025年发布的AI编程平台,首创“智能代理式编程”,支持自然语言驱动的全栈开发。通过仓库级理解、多智能体协同与云端沙箱执行,实现从需求到上线的端到端自动化,大幅提升研发效率,重塑程序员角色,引领AI原生开发新范式。
815 156
|
2天前
|
数据采集 缓存 数据可视化
Android 无侵入式数据采集:从手动埋点到字节码插桩的演进之路
本文深入探讨Android无侵入式埋点技术,通过AOP与字节码插桩(如ASM)实现数据采集自动化,彻底解耦业务代码与埋点逻辑。涵盖页面浏览、点击事件自动追踪及注解驱动的半自动化方案,提升数据质量与研发效率,助力团队迈向高效、稳定的智能化埋点体系。(238字)
244 156
|
3天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
10天前
|
机器人 API 调度
基于 DMS Dify+Notebook+Airflow 实现 Agent 的一站式开发
本文提出“DMS Dify + Notebook + Airflow”三位一体架构,解决 Dify 在代码执行与定时调度上的局限。通过 Notebook 扩展 Python 环境,Airflow实现任务调度,构建可扩展、可运维的企业级智能 Agent 系统,提升大模型应用的工程化能力。
|
人工智能 前端开发 API
前端接入通义千问(Qwen)API:5 分钟实现你的 AI 问答助手
本文介绍如何在5分钟内通过前端接入通义千问(Qwen)API,快速打造一个AI问答助手。涵盖API配置、界面设计、流式响应、历史管理、错误重试等核心功能,并提供安全与性能优化建议,助你轻松集成智能对话能力到前端应用中。
795 154