2011年3月25日 星期五

大樂透PART2

  程式設計工藝大師
import java.awt.*;
import java.awt.event.*;
public class AWT extends Frame implements ActionListener
{
//static Frame myfrm=new Frame("Button class");
//static AWT myfrm=new AWT("Frame 1 ");
static Button btn1=new Button("Button 1");
static TextField tbx1=new TextField("TextField");
static TextField tbx2=new TextField("TextField");
static TextField tbx3=new TextField("TextField");
static TextField tbx4=new TextField("TextField");
static TextField tbx5=new TextField("TextField");
static TextField tbx6=new TextField("TextField");
static TextField tbx7=new TextField("TextField"); 
public static void main(String args[])
{
AWT myfrm=new AWT();
FlowLayout f=new FlowLayout();
myfrm.setLayout(f);
myfrm.setSize(250,150);
btn1.addActionListener(myfrm);
myfrm.add(btn1,f);
myfrm.add(tbx1,f);
myfrm.add(tbx2,f);
myfrm.add(tbx3,f);
myfrm.add(tbx4,f);
myfrm.add(tbx5,f);
myfrm.add(tbx6,f);
myfrm.add(tbx7,f);
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int rn,a,b,c,d,k,f;
rn=(int) (Math.random()*49) ;
a=(int) (Math.random()*49) ;
b=(int) (Math.random()*49) ;
c=(int) (Math.random()*49) ;
d=(int) (Math.random()*49) ;
k=(int) (Math.random()*49) ;
f=(int) (Math.random()*49) ;
String stringValue = Integer.toString(rn);
String a1 = Integer.toString(a);
String a2 = Integer.toString(b);
String a3 = Integer.toString(c);
String a4 = Integer.toString(d);
String a5 = Integer.toString(k);
String a6 = Integer.toString(f);
System.out.println(rn );
System.out.println(a );
System.out.println(b );
System.out.println(c );
System.out.println(d );
System.out.println(k );
System.out.println(f );
tbx1.setText( stringValue );
tbx2.setText( a1 );
tbx3.setText( a2 );
tbx4.setText( a3 );
tbx5.setText( a4 );
tbx6.setText( a5 );
tbx7.setText( a6 );

}
}



2011年3月18日 星期五

大樂透



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

public class ButtonText extends JFrame implements ActionListener {
 
    public static void main(String[] args) {
    ButtonText test = new ButtonText();
}
ButtonText()
{
    JFrame frame=new JFrame("Button Frame");
   
    JButton button1 = new JButton("Submit");
    JButton button2 = new JButton("Submit");
   
button1.addActionListener(this);
button2.addActionListener(this);
    
getContentPane().add(button1); 
getContentPane().add(button2);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    setSize(200,100);
    setVisible(true);
  
    
}

public void actionPerformed(ActionEvent e)
{
int ra,rb,rc,rd,re,rf,rg;
ra=(int)(Math.random()*49+1);
rb=(int)(Math.random()*49+1);
rc=(int)(Math.random()*49+1);
rd=(int)(Math.random()*49+1);
re=(int)(Math.random()*49+1);
rf=(int)(Math.random()*49+1);
rg=(int)(Math.random()*49+1);
System.out.println(ra);
System.out.println(rb);
System.out.println(rc);
System.out.println(rd);
System.out.println(re);
System.out.println(rf);
System.out.println(rg);

}

2011年3月11日 星期五

checkbox


Frame frame = new Frame("Check Box Frame");
   
   
    //frame.setSize(400, 400);
   
    //frame.setVisible(true);
 
   
       public static void main(String[] args) { 
    // Work2 test = new Work2();
    // getContentPane().add(mybutton);
  
       Frame frame=new Frame("Button Frame");      
       frame.setSize(800,600);
       frame.setVisible(true);
       Button button = new Button("Submit");
       frame.add(button);
       frame.setLayout(new FlowLayout());
       button.setSize(500,200);
       button.setVisible(true);
       Checkbox chk = new Checkbox("This is the Check Box");
       frame.add(chk);
       chk.setSize(30,30);
       chk.setVisible(true);
      

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


       } 
   
       // 用建構方法來建立元件、將元件加入視窗、顯示視窗 
        public Work2() { 
        /* setTitle("Listener 示範");    // 設定視窗標題 
        Button mybutton = new Button("換個標題"); 
   
         // 通知按鈕物件:本物件要當傾聽者 
        mybutton.addActionListener(this); 
   
         getContentPane().add(mybutton); 
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
         setSize(SizeW,SizeH); 
         setVisible(true);*/ 
       } 
   
       public void actionPerformed(ActionEvent e) { 
           SizeW = (int)(SizeW * 2); 
           SizeH = (int)(SizeH * 2);   
          //setSize(SizeW,SizeH); 
       } 
   
 }

2011年3月3日 星期四