import java.awt.event.ActionListener
import javax.swing.*
public class test extends JFrame{
String[] student
JLabel jl
test(String[] s){
student=s
JPanel jp=new JPanel()
JButton jb=new JButton("叫号")
jl=new JLabel()
jp.add(jb)
jp.add(jl)
this.getContentPane().add(jp)
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jl.setText(student[(int)Math.floor(Math.random()*50)])
}
})
this.setTitle("叫号器")
this.setSize(200,100)
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
this.setLocationRelativeTo(null)
this.setVisible(true)
}
public static void main(String[] args)throws Exception {
String[] student=new String[50]
for (int i = 0i <student.lengthi++) {
student[i] = "小"+(int)Math.floor(Math.random()*50)
}
new test(student)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)