520写的小程序

只能点击我喜欢你,不能点击不喜欢你!!!

package com.y;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class CatchButtonGameV1 extends JFrame {
    /**
     *
     */
    private static final long serialVersionUID = -1273807998666343586L;
    /**
     *
     */
    public JButton button=new JButton("显示");
    public JButton[] J = new JButton[11];
    public Random random = new Random();
    public int randomInt=random.nextInt(9);
    public CatchButtonGameV1() {
        this.setTitle("Catch me if you can!");
        this.getContentPane().setLayout(new GridLayout(3, 3));
        for (int i = 0; i < 11; i++) {
        J[i] = new JButton();
        J[i].addMouseListener(new M0l());
        add(J[i]);
        }
        J[randomInt].setText("不喜欢我!!!");

         pack();
        setSize(700, 700);
        setVisible(true);
    }

    public static void main(String[] args) {
        //new CatchButtonGameV1();
        CatchButtonGameV1 s=new CatchButtonGameV1();
        s.ShowDIalog();
    }
    //mouse click listen
     public JButton temp2 = new JButton("喜欢我!!");
     public void ShowDIalog(){
        //setLayout(new FlowLayout());
        add(temp2);
        temp2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                JOptionPane.showMessageDialog(null,"嘻嘻,好开森");
            }
        });
        setVisible(true);
        setSize(600,600);
    }
    class M0l implements MouseListener {

        public void mouseClicked(MouseEvent e) {
            temp2 = (JButton) e.getSource();
            if(temp2.getText().equals("不喜欢我!!!")){
                temp2.setText("");
            }else{
                J[randomInt].setText("huhuilan");
            }
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {//鼠标移动过
            JButton temp = (JButton) e.getSource();
            if (temp.getText().equals("不喜欢我!!!")) {
            temp.setText("");
            do {
            randomInt = random.nextInt(9);
            } while (temp == J[randomInt]);
            J[randomInt].setText("不喜欢我!!!");
            }
    }

    public void mouseExited(MouseEvent e) {
        }
    }
}

原文地址:https://www.cnblogs.com/springcloud/p/9063401.html

时间: 2024-08-30 17:15:29

520写的小程序的相关文章

没有基础也能写个小程序

文章记录了小程序的设计思路,介绍了使用的技术,描述了提交审核的故事,还提供了最终的完整源码 背景说明 微信小程序自从发布以来就占据着超高的话题热度,一直以来都想开发一款自己的小程序,但苦于不懂前端迟迟没有开始.偶然发现了ColorUI这个开源的小程序组件库,界面好看且提供Demo,心中狂喜马上动手 做个什么小程序呢?想了一圈这半年多一直坚持在写技术文章,为此开通了微信公众号,因为公众号查看文章列表不友好,且不方便在微信以外的渠道传播,我又利用Github Pages搭建了运维咖啡吧网站主页,就想

Python:每天写点小程序

每天写点python小程序,下面是对一个txt文件的 里面的字数的统计,看的其他人的 1 file_name="E:\movie.txt" 2 #Python学习群125240963 3 4 5 line_counts=0 6 7 word_counts=0 8 9 character_counts=0 10 11 12 13 with open(file_name,"r") as f: 14 15 for line in f: 16 17 words=line.s

用mpvue写微信小程序时,webview跳转外部链接,再跳转回来需要点两次返回箭头才能跳转

问题描述: 给公司做微信小程序时遇到了这个问题,用mpvue框架搭建的小程序,从首页点击进去,先跳转到一个中间页面,在中间页面放上webview链接到外部的H5页面,这时点击小程序左上角自带的返回按钮,第一次会跳转到空白页,再点一次才能跳转到首页. 首页: 详情页: 这时需要点击左上角的返回箭头两次,才能跳转到首页 解决办法: 小程序跳到外部页面方法: 1.从首页(index)跳转到中间页(template): goPage(id){ wx.navigateTo({url:'../templat

从7点到9点写的小程序(用了模块导入,python终端颜色显示,用了点局部和全局可变和不可变作用域,模块全是自定义)

未完待续的小程序 要是能做的好看为啥不做的好看 在同目录下生成程序 1.程序文件 run.py from login import login from register import register from balance_enquiry import balance_enquiry from top_up import top_up msg_dict ={ '1':login, '0':register, '2':top_up, '3':balance_enquiry, 'q':'qui

实现自己写的小程序富文本编辑以及展示,不跟PC端的兼容,但是可以在pc端显示以及修改,一旦修改,小程序不再做解析

富文本结构: 1 <div class="detail_box"> 2 <ul> 3 <li v-for="(item4,index4) in detailAry" :key="index4"> 4 <!-- 文字 --> 5 <div class="detail_list"> 6 <div class="list_t"> 7 <

利用 Makefile 写的小程序

1.建立一个工程 2.写一个进度条的程序(原理就是在同一位置重复打印某一个字符(变化),达到动态显示的效果) 所以说我们这里只用回车'\r',覆盖这一行以前的输出,重新向缓冲区写数据刷新缓冲区,就能达到动态显示的目的: 效果图如下: 3.在工程下新建一个叫做 Makefile 的文件(M 也可以小写),并用 vim 编辑 4.运行 make 得到 ProgressBar 可执行文件,运行 make clean 清除可执行文件 这里奉上一篇博客,博客中详细介绍了:Makefile ,make 的使

代写Java小程序: Finding customer clusters at the Telco

There can be no extensions to this date. All assignments for this subject for this semester MUST be submitted by the 29th March. No Exceptions. Previously, management have been quite directed about what they were looking for and what they wanted to p

用android去写一个小程序

前言: 软工的一个小作业:实现"黄金分割小游戏", 需要结对编程,队友:陈乐云(http://www.cnblogs.com/clyln/),用时两天. 早期思路设计: 采用键值对的形式,以Map作为存储结构.优点:能够将数据与用户对应,缺点:采用java实现过于复杂,工程量过大,需要消耗大量资源,类型转换容易出错. 后期思路设计: 采用二维数组:第一行用于存储用户输入原始数据,第二行用于存储中间数据(第一行的与G值做差的绝对值),第三行用于保存用户得分. 优点:实现简单,易于运算 分

写个小程序查看500以内的质数

''' 写一个500以内的Eratosthenes筛法找出全部素数 ''' class node(object): def __init__(self,num): self.visited = False self.isPrime = False self.num = num matrix = [node(i+1) for i in range(500)] count = 0 def isPrime(num): for i in range(2,int(num**0.5)+1): if(num