自己點自己專用點名器
package className;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class RandomName {
Random rd = new Random();
JFrame rFrame=new JFrame("自己點自己TAT專用點名器");
JLabel name = new JLabel();
JButton btn = new JButton("開始點名");
String[] stuName={"宋雲飛1","宋雲飛2","宋雲飛3","宋雲飛4","宋雲飛5","宋雲飛6","宋雲飛7"};
public void init()
{
JLabel jt= new JLabel("T15專用點名器");
name.setHorizontalAlignment(SwingConstants.CENTER);
jt.setHorizontalAlignment(SwingConstants.CENTER);
jt.setFont(new java.awt.Font("T15專用點名器",2,40));
btn.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{
String n=getRandomName();
name.setText(n);
name.setFont(new java.awt.Font(n,2,40));
name.setForeground(Color.blue); } });
Container p = this.rFrame.getContentPane();
p.setLayout(new BorderLayout(3,1));
p.add(jt,BorderLayout.NORTH);
p.add(name,BorderLayout.CENTER);
p.add(btn,BorderLayout.SOUTH);
rFrame.pack();
rFrame.setSize(320, 320);
rFrame.setVisible(true);
}
public String getRandomName()
{ int x = 0; x = rd.nextInt(stuName.length);
return stuName[x];
}
public static void main(String[] args)
{ RandomName rn=new RandomName();
rn.init();
} }
自己點自己專用點名器