每日一單字: smile !
step1
import java.awt.*;
import java.awt.event.*;
public class ButtonText {
public static void main(String[] args) {
Frame frame=new Frame("Button Frame");
Button button = new Button("Submit");
frame.add(button);
frame.setLayout(new FlowLayout());
frame.setSize(200,100);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
step2
Frame frame=new Frame("Button Frame");
Button button1 = new Button("Submit");
frame.add(button1);
frame.setLayout(new FlowLayout());
frame.setSize(200,100);
frame.setVisible(true);
System.out.println("wait");
System.exit(0);
}
}
/* frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}*/
step3
Frame frame=new Frame("Button Frame");
Button button1 = new Button("Submit");
Button button2 = new Button("Submit");
frame.add(button1);
frame.add(button2);
frame.setLayout(new FlowLayout()); //排列
frame.setSize(200,100);
frame.setVisible(true);
System.out.println("wait");
System.exit(0);
step4
http://www.idevelopment.info/data/Programming/java/swing/AWTExample.java
step5
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonText {
public static void main(String[] args){
ButtonText test = new ButtonText();
}
ButtonText(){
/*
Frame frame=new Frame("Button Frame");
Button button1 = new Button("Submit");
Button button2 = new Button("Submit");
button1.addActionListener(this);
frame.add(button1);
frame.add(button2);
frame.setLayout(new FlowLayout()); //排列
frame.setSize(200,100);
frame.setVisible(true);
System.out.println("wait");
System.exit(0);
*/
}
}
step6
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();
}
public ButtonText(){
//Frame frame=new Frame("Button Frame");
JButton button1 = new JButton("Submit");
JButton button2 = new JButton("Submit2");
button1.setSize(25,25);
button2.setSize(25,25);
button1.addActionListener(this);
getContentPane().add(button1);
getContentPane().add(button2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.add(button1);
//frame.add(button2);
setLayout(new FlowLayout()); //排列
setSize(200,100);
setVisible(true);
//System.out.println("wait");
//System.exit(0);
}
public void actionPerformed(ActionEvent e) {
}
}
/* frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}*/
final step
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();
}
public ButtonText(){
//Frame frame=new Frame("Button Frame");
JButton button1 = new JButton("Submit");
JButton button2 = new JButton("Submit2");
button1.setSize(25,25);
button2.setSize(25,25);
button1.addActionListener(this);
getContentPane().add(button1);
getContentPane().add(button2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.add(button1);
//frame.add(button2);
setLayout(new FlowLayout()); //排列
setSize(500,500);
setVisible(true);
//System.out.println("wait");
//System.exit(0);
}
public void actionPerformed(ActionEvent e) {
/*int t1,t2,t3,t4,t5,t6,t7;
t1=(int)(Math.random()*49+1);
t2=(int)(Math.random()*49+1);
t3=(int)(Math.random()*49+1);
t4=(int)(Math.random()*49+1);
t5=(int)(Math.random()*49+1);
t6=(int)(Math.random()*49+1);
t7=(int)(Math.random()*49+1);
System.out.println(t1+"\u0020"+t2+"\u0020"+t3+"\u0020"+t4+"\u0020"+t5+"\u0020"+t6+"\u0020"+t7);*/
int loto[]=new int[7];
for(int i=0;i<loto.length;i++)
{
int tmp;
boolean find=false;
do{
tmp=(int)((Math.random()*49)+1);
for(int j=0;j<loto.length;j++)
{
if(tmp==loto[j])
{
find=true;
break;
}
}
}while(find!=false);
loto[i]=tmp;
if(i==6)
System.out.println("特別號:"+loto[i]);
else
System.out.println("第"+(i+1)+"個開獎號碼:"+loto[i]);
}
}
}
/* frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}*/
沒有留言:
張貼留言