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();
}
} 展开
展开全部
给楼主改了一下
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 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |