zoukankan      html  css  js  c++  java
  • 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) {
            }
        }
    }
  • 相关阅读:
    .net SMTP发送Email 更新(可带附件)
    Ext JS4百强应用: 做可编辑的,可checked的treegrid--第11强
    使你更有思想的20本书
    Sencha Architect 2 的使用
    Test SRM Level One: TemperatureScales
    Test SRM Level Two: CountExpressions, Brute Force
    JPDA 利用Eclipse和Tomcat进行远程调试 --转
    非对称加密算法RSA--转
    java/php/c#版rsa签名以及java验签实现--转
    JAVA/PHP/C#版RSA验签--转
  • 原文地址:https://www.cnblogs.com/springcloud/p/9063401.html
Copyright © 2011-2022 走看看