2011年3月25日 星期五

程式設計工藝大師

JAVA-6

// with event
//AWT, Button類別 有ActionListener
import java.awt.*;
import java.awt.event.*;
public class AwtTest extends Frame implements ActionListener
{
//static Frame myfrm=new Frame("Button class"); // Java Class Frame
//static AwtTest myfrm=new AwtTest("Button class"); // Java Class Frame
static Button btn1=new Button("Button 1"); // 建立1按鈕物件
//static Button btn2=new Button("Button 2"); // 建立2按鈕物件
static TextField tbx1=new TextField("TextField  1"); // 建立1文字方塊物件
static TextField tbx2=new TextField("TextField  2"); // 建立1文字方塊物件
static TextField tbx3=new TextField("TextField  3"); // 建立1文字方塊物件
static TextField tbx4=new TextField("TextField  4"); // 建立1文字方塊物件
static TextField tbx5=new TextField("TextField  5"); // 建立1文字方塊物件
static TextField tbx6=new TextField("TextField  6"); // 建立1文字方塊物件
static TextField tbx7=new TextField("TextField  7"); // 建立1文字方塊物件
static TextField tbx8=new TextField("TextField  8"); // 建立1文字方塊物件

public static void main(String args[])
{
AwtTest myfrm=new AwtTest();
FlowLayout border=new FlowLayout();
myfrm.setLayout(border);
myfrm.setSize(250,150);
btn1.addActionListener(myfrm);
myfrm.add(btn1); // 在視窗內加入按鈕1
//myfrm.add(btn2); // 在視窗內加入按鈕2
myfrm.add(tbx1); // 在視窗內加入按鈕2
myfrm.add(tbx2);
myfrm.add(tbx3);
myfrm.add(tbx4);
myfrm.add(tbx5);
myfrm.add(tbx6);
myfrm.add(tbx7);
myfrm.add(tbx8);
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)

 int a,b,c,d,h,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);
h=(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(h);
System.out.println(f);
System.out.println(g);
String stringvalue1=Integer.toString(a);
String stringvalue2=Integer.toString(b);
String stringvalue3=Integer.toString(c);
String stringvalue4=Integer.toString(d);
String stringvalue5=Integer.toString(h);
String stringvalue6=Integer.toString(f);
String stringvalue7=Integer.toString(g);
System.out.println(a );
tbx1.setText(stringvalue1);
tbx2.setText(stringvalue2);
tbx3.setText(stringvalue3);
tbx4.setText(stringvalue4);
tbx5.setText(stringvalue5);
tbx6.setText(stringvalue6);
tbx7.setText(stringvalue7);
}
}
無法移除時可以按CTRL+C即可跳出

程式設計工藝大師

程式設計工藝大師

2011年3月18日 星期五

JAVA-4

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,b,c,d,h,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);
h=(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(h);
System.out.println(f);
System.out.println(g);
}
}
Math.random() 亂數的使用

2011年3月3日 星期四

JAVA-4

class Test2
{
public static void main(String[] args)
{
int x,y,z,s,t;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
z=Integer.parseInt(args[2]);
s=Integer.parseInt(args[3]);
t=x*z+y*s;
System.out.println(t);

}

2011年2月25日 星期五

JAVA-3

class Test{
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日 星期五

JAVA-1.1

一開始找不到路徑,把整個程式移到d槽
再把記事本檔案移到bin資料夾裡面
就可解決了