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() 亂數的使用

沒有留言:

張貼留言