2011年3月25日 星期五

JAVA-15

這是今天作業的程式碼
一開始遇到很多問題
後來經過問同學後才知道
因為使用了flowlayout之後
之前的borderlayout就沒有再用了
要用掉
用掉之後因為沒有borderlayout
所以方位也不用了

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

public class Test3 extends Frame implements ActionListener
{

static Frame frame=new Frame("Button class");
static Button button1=new Button("Button 1");
//static Button button2=new Button("Button 2");
static TextField tbx1=new TextField("TextField1");
static TextField tbx2=new TextField("TextField2");
static TextField tbx3=new TextField("TextField3");
static TextField tbx4=new TextField("TextField4");
static TextField tbx5=new TextField("TextField5");
static TextField tbx6=new TextField("TextField6");
static TextField tbx7=new TextField("TextField7");
static TextField tbx8=new TextField("TextField8");



public static void main(String args[])
{
Test3 frame=new Test3();
FlowLayout border=new FlowLayout();
frame.setLayout(border);
frame.setSize(400,400);
button1.addActionListener(frame);
frame.add(button1);
//frame.add(button2, border);
frame.add(tbx1, border);
frame.add(tbx2);
frame.add(tbx3);
frame.add(tbx4);
frame.add(tbx5);
frame.add(tbx6);
frame.add(tbx7);
frame.add(tbx8);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int a;
int b;
int c;
int d;
int f;
int g;
int h;
a=(int) ((Math.random()*49)+1);
String stringValue1=Integer.toString(a);
b=(int) ((Math.random()*49)+1);
String stringValue2=Integer.toString(b);
c=(int) ((Math.random()*49)+1);
String stringValue3=Integer.toString(c);
d=(int) ((Math.random()*49)+1);
String stringValue4=Integer.toString(d);
f=(int) ((Math.random()*49)+1);
String stringValue5=Integer.toString(f);
g=(int) ((Math.random()*49)+1);
String stringValue6=Integer.toString(g);
h=(int) ((Math.random()*49)+1);
String stringValue7=Integer.toString(h);
System.out.println(a);
tbx2.setText(stringValue1);
System.out.println(b);
tbx3.setText(stringValue2);
System.out.println(c);
tbx4.setText(stringValue3);
System.out.println(d);
tbx5.setText(stringValue4);
System.out.println(f);
tbx6.setText(stringValue5);
System.out.println(g);
tbx7.setText(stringValue6);
System.out.println(h);
tbx8.setText(stringValue7);
}
}
程式設計工藝大師http://tccnchsu.blogspot.com/
這是老師的BLOG
有誰參觀到我網誌的可以去看看

JAVA-14


這是今天的作業
一樣是樂透號碼
雖然多一個匡匡= =
但是也算是正確的

JAVA-13














這是今天的上課內容
做出borderlayout的button

2011年3月18日 星期五

JAVA-12

這是今天上課作業的程式碼


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();
}
ButtonText( )
{
JButton mybutton1 = new JButton("Submit");
JButton mybutton2 = new JButton("Submit");
mybutton1.addActionListener(this);
//Container contentPane = frame.getContentPane();
//contentPane.add(mybutton1);
//contentPane.add(mybutton2);
getContentPane().add(mybutton1);
getContentPane().add(mybutton2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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;
int b;
int c;
int d;
int f;
int g;
int h;
a=(int) ((Math.random()*49)+1);
b=(int) ((Math.random()*49)+1);
c=(int) ((Math.random()*49)+1);
d=(int) ((Math.random()*49)+1);
f=(int) ((Math.random()*49)+1);
g=(int) ((Math.random()*49)+1);
h=(int) ((Math.random()*49)+1);
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}

}

JAVA-11


這是今天的作業
產生樂透的號碼

2011年3月17日 星期四

JAVA-10















雖然上課的時候沒有做出來
但是我回家之後有研究如何做
終於在禮拜四比較有空時研究出來了

2011年3月11日 星期五

JAVA-9


這是今天教button的程式

2011年3月3日 星期四

JAVA-8
















這是今天的作業
一樣很完美的完成了










class Test20110304
{
public static void main(String[] args)
{
int a,b,c,d,e;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
d=Integer.parseInt(args[3]);
e=a*c+b*d;
System.out.println(e);
}
}

JAVA-7


這也是今天的練習
這是兩個數加在一起的程式
一開始有點錯誤
原來是英文打錯~o~
後來發現就沒問題了

JAVA-6


這是今天老師教我們新的課程
正在練習中