[java]代码库
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package myframe;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class question extends JFrame implements ActionListener{
JLabel tip;
JButton sure ,cancel ;
int count;
question (){
tip = new JLabel("那么问题来了:你是不是狗??");
tip.setBounds(100,10,200,100);
sure = new JButton("是");
sure.addActionListener(this);
sure.setBounds(100,100,60,35);
cancel = new JButton("否");
cancel.addActionListener(this);
cancel.setBounds(200,100,60,35);
this.add(tip);
this.add(sure);
this.add(cancel);
this.setLayout(null);
this.setLocation(500,200);
this.setSize(400,200);
this.setVisible(true);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
public static void main(String[] args) {
question q = new question();
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if(s.equals("是")){
JOptionPane.showMessageDialog(this,"你终于能正视自己了!!");
System.exit(0);
}else if(s.equals("否")){
count++;
if(count!=3||count!=10||count!=50||count!=51){
JOptionPane.showMessageDialog(this,"你应该认清现实!!");
}
if(count==3){
JOptionPane.showMessageDialog(this,"你已经按了3次了!!就此打住吧!");
}else if(count ==10){
JOptionPane.showMessageDialog(this,"好了,好了,已经十次了,既然你这么有毅力,就按到50次吧!");
}else if (count ==50){
JOptionPane.showMessageDialog(this,"恭喜你已经到达了50次!我也可以承认你不是狗了!可是距离成功还差一点!");
}else if(count ==51){
JOptionPane.showMessageDialog(this,"好吧!你赢了!虽然你不是狗,但你能按到50次,只能说明你傻!!");
System.exit(0);
}
}
}
}
中级程序员
by: xuetongbing 发表于:2015-03-19 15:11:02 顶(0) | 踩(0) 回复
额。。。这个也太无聊了吧
回复评论