2011年3月18日 星期五

Code for Blogger

FORMAT MY SOURCE CODE FOR BLOGGING

Test

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonText  extends JFrame
                                       implements ActionListener {
  public static void main(String[] args){
ButtonText test = new ButtonText();
}
 public ButtonText(){

    //Frame frame=new Frame("Button Frame");
    JButton button1 = new JButton("Submit");
    JButton button2 = new JButton("Submit2");
   button1.setSize(25,25);
   button2.setSize(25,25);
    button1.addActionListener(this);
    getContentPane().add(button1);
    getContentPane().add(button2);
   
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.add(button1);
    //frame.add(button2);
    setLayout(new FlowLayout()); //排列
    setSize(500,500);
    setVisible(true);
    //System.out.println("wait");
    //System.exit(0);
}
public void actionPerformed(ActionEvent e) {
 /*int t1,t2,t3,t4,t5,t6,t7;
t1=(int)(Math.random()*49+1);
t2=(int)(Math.random()*49+1);
t3=(int)(Math.random()*49+1);
t4=(int)(Math.random()*49+1);
t5=(int)(Math.random()*49+1);
t6=(int)(Math.random()*49+1);
t7=(int)(Math.random()*49+1);
 System.out.println(t1+"\u0020"+t2+"\u0020"+t3+"\u0020"+t4+"\u0020"+t5+"\u0020"+t6+"\u0020"+t7);*/
int loto[]=new int[7];
  for(int i=0;i<loto.length;i++)
  {
            int tmp;
            boolean find=false;
            do{
             tmp=(int)((Math.random()*49)+1);
             for(int j=0;j<loto.length;j++)
             {
              if(tmp==loto[j])
              {
                  find=true;
                  break;
              }
              }
            }while(find!=false);
            loto[i]=tmp;
            if(i==6)
            System.out.println("特別號:"+loto[i]);
            else
    System.out.println("第"+(i+1)+"個開獎號碼:"+loto[i]);
  }
}
}

 /*   frame.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        System.exit(0);
      }
    });
  }
}*/

沒有留言:

張貼留言