2011年3月25日 星期五

2011/03/25 java button

Java Class Frame
java 版面
BorderLayout



//AWT, Button類別
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("button1!!"); // 建立按鈕物件
static Button btn2=new Button("button2!!");  // 建立按鈕物件
static TextField fid1=new TextField("TextField!!");  // 建立文字方塊物件

public static void main(String args[])
{
AwtTest myfrm=new AwtTest();
BorderLayout border=new BorderLayout();
myfrm.setLayout(border);
myfrm.setSize(280,150);

btn1.addActionListener(myfrm);
myfrm.add(btn1,border.EAST); // 在視窗內加入按鈕
myfrm.add(btn2,border.CENTER);
myfrm.add(fid1,border.WEST);
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int rn;
rn=(int) (Math.random()*49) ;
System.out.println(rn );
}
}

===================================================================
作業  做七個 TextField
呈現1種數字
//AWT, Button類別
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("button1!!"); // 建立按鈕物件
//static Button btn2=new Button("button2!!");  // 建立按鈕物件
static TextField fid1=new TextField("TextField!!");  // 建立文字方塊物件
static TextField fid2=new TextField("TextField!!");
static TextField fid3=new TextField("TextField!!");
static TextField fid4=new TextField("TextField!!");
static TextField fid5=new TextField("TextField!!");
static TextField fid6=new TextField("TextField!!");
static TextField fid7=new TextField("TextField!!");
public static void main(String args[])
{
AwtTest myfrm=new AwtTest();
FlowLayout border=new FlowLayout();
//BorderLayout border=new BorderLayout();
myfrm.setLayout(border);
myfrm.setSize(280,150);

btn1.addActionListener(myfrm);
myfrm.add(btn1);
myfrm.add(fid1);
myfrm.add(fid2);
//myfrm.add(new TextField(20));
myfrm.add(fid3);
myfrm.add(fid4);
myfrm.add(fid5);
myfrm.add(fid6);
myfrm.add(fid7);
//myfrm.add(btn1,border.WEST); // 在視窗內加入按鈕
//myfrm.add(btn2,border.CENTER);
//myfrm.add(fid1,border.EAST);
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int rn,rb,rc,rd,re,rf,rg;
rn=(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(rn );
System.out.println(rb );
System.out.println(rc );
System.out.println(rd );
System.out.println(re );
System.out.println(rf );
System.out.println(rg );

//int rn;
//rn=(int) (Math.random()*49) ;
String stringValue = Integer.toString(rn) ;
String stringValue1 = Integer.toString(rb) ;
String stringValue2 = Integer.toString(rc) ;
String stringValue3 = Integer.toString(rd) ;
String stringValue4 = Integer.toString(re) ;
String stringValue5 = Integer.toString(rf) ;
String stringValue6 = Integer.toString(rg) ;
//System.out.println(rn );
fid1.setText(stringValue);
fid2.setText(stringValue1);
fid3.setText(stringValue2);
fid4.setText(stringValue3);
fid5.setText(stringValue4);
fid6.setText(stringValue5);
fid7.setText(stringValue6);

}
}

沒有留言:

張貼留言

Use google protocol buffers + QT +CMAKE

Protocol Buffers https://developers.google.com/protocol-buffers/ Serialize and ParseFrom https://www.jianshu....