2011年3月31日 星期四

2011/04/01 swing JFrame

改成swing 用Jxxxxxx
hoe to use java panel
http://download.oracle.com/javase/tutorial/uiswing/components/panel.html

color
http://www.java2s.com/Code/Java/Swing-JFC/Buttonactiontochangethepanelbackground.htm
======================================================
//AWT, Button Class
import java.awt.*;
import java.awt.event.*;

public class AwtTest extends Frame
{
static Frame myfrm=new Frame("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文字方塊物件

public static void main(String args[])
{
BorderLayout border=new BorderLayout();
myfrm.setLayout(border);
myfrm.setSize(250,150);
myfrm.add(btn1, border.EAST); // 在視窗內加入按鈕1
myfrm.add(btn2, border.CENTER); // 在視窗內加入按鈕2
myfrm.add(tbx1, border.WEST); // 在視窗內加入按鈕2
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int rn;
rn=(int) (Math.random()*49) ;
System.out.println(rn );
}
}
======================================================
--------------------------------------------------------------------------------------------------------
//AWT, JButton類別
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import javax.swing.JButton;
public class SwingJ extends JFrame
{
static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
static JTextField tbx1=new JTextField("JTextField  1"); // 建立1文字方塊物件
static JButton but1=new JButton("JButton  1"); // 建立1文字方塊物件
/*
// goes on to 26JButtons[] buttons = new JButton(numbers.length)
// create instance of each buttonfor (int i = 0; i < numbers.length; i++){buttons[i] = new JButton(numbers[i]);
// create buttons } String[] numbers = {"0", "1", "2", "3", 4", "5", "6", "7", "8", "9"};
// goes on to 26
*/
public static void main(String args[])
{
JButton buttons[]=new JButton[10];
String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
//GridBagLayout  border=new GridBagLayout ();
GridLayout border= new GridLayout(3,3);
GridLayout border2= new GridLayout(3,2);
JPanel p1 = new JPanel(border); //PREFERRED!
JPanel p2 = new JPanel(border2); //PREFERRED!
for (int i = 0; i < numbers.length; i++)
{
buttons[i] = new JButton(numbers[i]); // create buttons
p1.add(buttons[i], border); // 在視窗內加入按鈕1
}
myfrm.add(p1);
myfrm.add(tbx1);
myfrm.add(but1);



myfrm.setLayout(border);
myfrm.setSize(250,150);
// create instance of each button
//FlowLayout flow= new  FlowLayout();
// myfrm.add(tbx1, flow); // 在視窗內加入文字方塊
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
int rn;
rn=(int) (Math.random()*49) ;
System.out.println(rn );
}
}


// with event
//AWT, JButton類別 有ActionListener
//AWT, JButton類別
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingTestEvent extends JFrame implements ActionListener
{
//static JFrame myfrm=new JFrame("JButton class"); // Java Class JFrame
//static AwtTestEvent myfrm=new AwtTestEvent("JFrame 1 "); // Java Class JFrame
static JButton btn1=new JButton("JButton 1"); // 建立1按鈕物件
static JTextField tbx1=new JTextField("  "); // 建立1文字方塊物件
public static void main(String args[])
{
SwingTestEvent myfrm=new SwingTestEvent();
JButton buttons[]=new JButton[10];
String numbers[]  = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
//GridBagLayout  border=new GridBagLayout ();
GridLayout border= new GridLayout(3,3);
GridLayout border2= new GridLayout(1,2);
JPanel p1 = new JPanel(border); //PREFERRED!
for (int i = 0; i < numbers.length; i++)
{
buttons[i] = new JButton(numbers[i]); // create buttons
p1.add(buttons[i], border); // 在視窗內加入按鈕1
buttons[i].setBackground(Color.green);

}
myfrm.add(p1); // 在視窗內加入按鈕2
FlowLayout flow=new FlowLayout();
JPanel p2 = new JPanel(flow); //PREFERRED!
myfrm.setLayout(border);
myfrm.setSize(250,150);
btn1.addActionListener(myfrm);
p2.add(tbx1);
p2.add(btn1);
myfrm.add(p2); // 在視窗內加入按鈕2
myfrm.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
btn1.setBackground(Color.red);
//tbx1.setText("");
String stringValue;
stringValue=tbx1.getText();
//int intValue = Integer.parseInt(stringValue);
System.out.println(stringValue);
}
}

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);

}
}

2011年3月18日 星期五

2011/03/18 隨機7個樂透號碼

跑程式
做修改

做兩個BUTTOM

跑範例


作業 隨機7個樂透號碼
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 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 );
}
}




2011年3月3日 星期四

2011/03/04 java 相加

1.檢查
2.開始撰寫

3.大小寫 數字

4.輸出


5.字串

6.
7.string to int 
8.結果
class Test20110304
{
public static void main(String[] args)
{
int x,y,z,u,v;
x=Integer.parseInt(args[0]) ;
y=Integer.parseInt(args[1]) ;
u=Integer.parseInt(args[2]) ;
v=Integer.parseInt(args[3]) ;
z=x*u+y*v;
System.out.println(z);

}
}

Use google protocol buffers + QT +CMAKE

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