2011年3月25日 星期五

JAVA第六堂課





                                          一開始先參考別人的程式,一步一步改成自己想要的東西,
                                          不過不能照抄。
                                 

                                         JAVA 版面 → 可以參考版面的用法


 
           上面所圈的是建立多個按鈕的程式和文字方塊,
還有將他把放在適當的位置避免重疊

這次要直接在文字方塊上印出七個號碼,
程式如下。
    程式 :
import java.awt.*;
import java.awt.event.*;
public class AwtTest extends Frame implements ActionListener
{
static Frame myfrm=new Frame("Button class");
static Button btn=new Button("Button");
static TextField tf1=new TextField("TextField");
static TextField tf2=new TextField("TextField");
static TextField tf3=new TextField("TextField");
static TextField tf4=new TextField("TextField");
static TextField tf5=new TextField("TextField");
static TextField tf6=new TextField("TextField");
static TextField tf7=new TextField("TextField");
public static void main(String args[])
{
AwtTest myfrm=new AwtTest();
FlowLayout flow=new FlowLayout();
myfrm.setLayout(flow);
myfrm.setSize(200,150);
myfrm.add(btn,flow);
myfrm.add(tf1,flow);
myfrm.add(tf2,flow);
myfrm.add(tf3,flow);
myfrm.add(tf4,flow);
myfrm.add(tf5,flow);
myfrm.add(tf6,flow);
myfrm.add(tf7,flow);
btn.addActionListener(myfrm);
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int a,b,c,d,p,q,r;
a=(int)(Math.random()*49)+1;
b=(int)(Math.random()*49)+1;
c=(int)(Math.random()*49)+1;
d=(int)(Math.random()*49)+1;
p=(int)(Math.random()*49)+1;
q=(int)(Math.random()*49)+1;
r=(int)(Math.random()*49)+1;
String one= Integer.toString(a);
String two= Integer.toString(b);
String three= Integer.toString(c);
String four= Integer.toString(d);
String five= Integer.toString(p);
String six= Integer.toString(q);
String seven= Integer.toString(r);
tf1.setText(one);
tf2.setText(two);
tf3.setText(three);
tf4.setText(four);
tf5.setText(five);
tf6.setText(six);
tf7.setText(seven);
System.out.println();
}
}

2011年3月17日 星期四

JAVA 第五堂課

一開始先拿別人程式在修改,存檔時要用文字文件,
檔名要跟class後面一樣,最後的附檔用java,即完成。
設有兩個按鈕mybutton1、mybutton2,所以相對要新增
myframe.add(mybutton1)、myframe.add(mybutton1),打的時候
要注意有沒有把兩個按鈕設成一樣。 
                                               另存目標,當做參考用的程式。
                          這次要做點擊按鈕後,會一次跳出七個數字,介於1~49。
     程式 :
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

   public class ButtonText extends JFrame  
                 implements ActionListener { 

   public static void main(String[] args) {
    ButtonText text = new  ButtonText ( );
 }
   
 ButtonText ( )
 {
   
    JButton mybutton1 = new JButton("Submit");
    JButton mybutton2 = new JButton("Submit");
    mybutton1.addActionListener(this);
    mybutton2.addActionListener(this);
       getContentPane().add(mybutton1); 
       getContentPane().add(mybutton2); 
       setLayout(new FlowLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    setSize(200,100);
    setVisible(true);
    //System.out.println("wait");
     //System.exit(0);
  
}
public void actionPerformed(ActionEvent e)
 {
 int a,b,c,d,r,f,g ;
a =(int)(Math.random( )*49)+1;
b=(int)(Math.random( )*49)+1;
c =(int)(Math.random( )*49)+1;
d =(int)(Math.random( )*49)+1;
r =(int)(Math.random( )*49)+1;
f =(int)(Math.random( )*49)+1;
g =(int)(Math.random( )*49)+1;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(r);
System.out.println(f);
System.out.println(g);
}
  }
     


 

2011年3月11日 星期五

第四週


                                            一開始,先參考別人的程式碼(上圖),
                                                  再慢慢修改成自己想要的東西。

     這個禮拜是做按鈕視窗可打勾和可點擊按鈕的程式。
      
       JCheckBox : 用來設計可打勾按鈕
       mybutton.setSize(50,60) : 設定按鈕大小
       frame.add(mybutton1) : 增加mybutton1這個視窗
      
 
程式 :
       mport javax.swing.*;
       import java.awt.*; 
       import java.awt.event.*;  //  
   
        public class Work3 extends Frame  
                     implements ActionListener { 
   
     /** 
      * @param args 
      */
     //int act = 0;     // 
    // int SizeW = 210; 
     //int SizeH = 70; 
   
       public static void main(String[] args) { 
           //Work2 test = new Work2(); 
     Frame frame=new Frame("dhuf");
     frame.setSize(210,200);
     frame.setVisible(true);
     Button mybutton = new Button("Submit");
     mybutton.setSize(50,60);
     frame.add(mybutton);
    
     JCheckBox mybutton1 = new JCheckBox("1234");
     mybutton1.setSize(50,60);
     frame.add(mybutton1);

     

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

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

2011年3月3日 星期四

JAVA 第三堂課


   創建新的檔案後先儲存,檔案類型要選文字文件,檔名第一個字用大寫,後面副檔名是 
   txt, 之後記得將儲存的檔案,副檔名改成java即可。

今天教一些語法,然後上面是這次的作業,就是矩陣相乘的程式執行結果。
Integer.parseInt( ):宣告成整數   class : 類別
main : 主要方法    String : 字串  public : 公用(不然別人無法使用)
void : 不用回傳的意思


程式:
class Text20110304
 {
 
public static void main(String[] args)
{
int x,y,z,a,b;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
a=Integer.parseInt(args[2]);
b=Integer.parseInt(args[3]);
z=x*a+y*b;

System.out.println(z);
    }

 }

2011年2月25日 星期五

JAVA的第二堂課

這個禮拜教基本的語法概念,這是聖誕樹圖。
 System.out.println 系統輸出、印出
 static 靜態的

程式:
 class Text
 {
   public static void main(String[] args)
  {
   System.out.println("____*____");
   System.out.println("___***___");
   System.out.println("__*****__");
   System.out.println("_*******_");
   System.out.println("____*____");
   System.out.println("____*____");
  }
 }

2011年2月18日 星期五

作業

   一開始因為路徑問題,所以一直執行失敗,後來把資料放在我的文件夾,才執行成功。

2011年2月17日 星期四

JAVA的第一堂課

一、
1.為何why要選修這門課?(動機)
  答:因為專題是做跟程式有關的,要製作遊戲的程式,所以想盡力學一些程式相關的課程,
 希望可以從各個方面學到一些東西,因為基礎不是很好,只能夠努力試試看。
2.希忘從這門課獲得那些知識?(目標)
   答:希望能學到寫程式的技巧,因為每次程式只要有點複雜,就會覺得很難,所以這是我的
目標。
3.我要如何修習這一門課?(態度與方法)
   答:上課用心聽講,能練習的時候,盡量練習,因為之前別堂程式課都過度懶散,以致於都學不好,所以這次一定要努力學好它。
二、
 請問您畢業後,如果找不到工作,您會花錢去上 "Java程式設計實力精修班" 課程嗎? 為甚   麼?
  答:應該不會。因為在學生時期,明明有機會上到JAVA課,假如不能夠把它認真地融入自己的腦袋裡,或者是可能認真過,卻無法得到相當的效力,如果真的是如此,那你之後在去上實力精修班,可能也沒辦法學好,只是白花錢的,所以態度是相當重要的,這就是我認為不會去的原因。