java随机点名系统
这是我写的一个随机点名系统的gui,因为是刚学,错的一塌糊涂,希望哪位高手帮我看下importjava.awt.*;importjava.util.*;publiccla...
这是我写的一个随机点名系统的gui,因为是刚学,错的一塌糊涂,希望哪位高手帮我看下
import java.awt.*;
import java.util.*;
public class RandomClassgui extends WindowAdapter implements ActionListener{
Frame f = new Frame("点名系统");
Button startB;
public void display() {
f.setSize(300,200);
f.setLocation(200,140);
f.setBackground(Color.lightGray);
startB = new Button("开始点名");
startB.addActionListener(this);
f.addWindowListener(this);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==startB);
String[] namelist={"小明","小白","小黑","小黄","小兰","小草","小丽","兔子","巫妖","船长","剑圣","冰女"};
int randomNum=(int)(Math.random()*namelist.length);
System.out.println(namelist[randomNum]);
}
public static void main(String args[]){
new RandomClassgui().display();
}
} 展开
import java.awt.*;
import java.util.*;
public class RandomClassgui extends WindowAdapter implements ActionListener{
Frame f = new Frame("点名系统");
Button startB;
public void display() {
f.setSize(300,200);
f.setLocation(200,140);
f.setBackground(Color.lightGray);
startB = new Button("开始点名");
startB.addActionListener(this);
f.addWindowListener(this);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==startB);
String[] namelist={"小明","小白","小黑","小黄","小兰","小草","小丽","兔子","巫妖","船长","剑圣","冰女"};
int randomNum=(int)(Math.random()*namelist.length);
System.out.println(namelist[randomNum]);
}
public static void main(String args[]){
new RandomClassgui().display();
}
} 展开
1个回答
展开全部
给楼主改了一下
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
public class RandomClassgui extends WindowAdapter implements ActionListener{
Frame f = new Frame("点名系统");
Button startB;
public void display() {
f.setSize(300,200);
f.setLocation(200,140);
f.setBackground(Color.lightGray);
startB = new Button("开始点名");
startB.addActionListener(this);
f.addWindowListener(this);
f.add(startB);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==startB);
String[] namelist={"小明","小白","小黑","小黄","小兰","小草","小丽","兔子","巫妖","船长","剑圣","冰女"};
int randomNum=(int)(Math.random()*namelist.length);
System.out.println(namelist[randomNum]);
}
public static void main(String args[]){
new RandomClassgui().display();
}
}
其实没有改太多的地方
只是加了一句
f.add(startB);
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
public class RandomClassgui extends WindowAdapter implements ActionListener{
Frame f = new Frame("点名系统");
Button startB;
public void display() {
f.setSize(300,200);
f.setLocation(200,140);
f.setBackground(Color.lightGray);
startB = new Button("开始点名");
startB.addActionListener(this);
f.addWindowListener(this);
f.add(startB);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==startB);
String[] namelist={"小明","小白","小黑","小黄","小兰","小草","小丽","兔子","巫妖","船长","剑圣","冰女"};
int randomNum=(int)(Math.random()*namelist.length);
System.out.println(namelist[randomNum]);
}
public static void main(String args[]){
new RandomClassgui().display();
}
}
其实没有改太多的地方
只是加了一句
f.add(startB);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
作为北京饼干科技有限公司的工作人员,关于AIPPT免费生成PPT的功能,我可以简要介绍如下:AIPPT是一款基于人工智能技术的PPT制作工具,它为用户提供了免费生成PPT的便捷服务。用户只需简单输入PPT的主题或内容大纲,AIPPT便能智能...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询