Java 在JLabel上遍历ArrayList字符串
如果我有一个类,其中包含一系列用于测验的问题,那么当每个人正确回答一个问题时,我如何让一个JLabel(包含在单独的类中)以显示的方式完成每个问题 澄清一下, -JLabel显示ArrayList中的第一个字符串 -此人正确回答了问题 -JLabel然后在ArrayList中显示第二个字符串 我的ArrayList代码是Java 在JLabel上遍历ArrayList字符串,java,arraylist,jlabel,Java,Arraylist,Jlabel,如果我有一个类,其中包含一系列用于测验的问题,那么当每个人正确回答一个问题时,我如何让一个JLabel(包含在单独的类中)以显示的方式完成每个问题 澄清一下, -JLabel显示ArrayList中的第一个字符串 -此人正确回答了问题 -JLabel然后在ArrayList中显示第二个字符串 我的ArrayList代码是 import java.util.*; public class Questions { public static void main(String[] args) {
import java.util.*;
public class Questions {
public static void main(String[] args) {
ArrayList<String> SPOquestions = new ArrayList<String>(); // adding the sports questions for the quiz
SPOquestions.add("Who won the 2005 Formula One World Championship?");
SPOquestions.add("Which team has the most Formula One Constructors titles?");
SPOquestions.add("In what year did Roger Federer win his first 'Grand Slam'?");
SPOquestions.add("How many 'Grand Slams' has Rafael Nadal won?");
SPOquestions.add("Who has scored the most amount of goals in the Premier League?");
SPOquestions.add("Who has won the most World Cups in football?");
SPOquestions.add("How many MotoGP titles does Valentino Rossi hold?");
SPOquestions.add("Who was the 2013 MotoGP champion?");
SPOquestions.add("Who won the 2003 Rugby World Cup?");
SPOquestions.add("In rugby league, how many points are awarded for a try?");
SPOquestions.add("Who is the youngest ever snooker World Champion?");
SPOquestions.add("In snooker, what is the highest maximum possible break?");
SPOquestions.add("How many majors has Tiger Woods won?");
SPOquestions.add("In golf, what is the tournament between the USA and Europe called?");
SPOquestions.add("How many World Championships has darts player Phil Taylor won?");
SPOquestions.add("What is the maximum possible amount of points a player can earn from throwing three darts?");
SPOquestions.add("How many gold medals did Michael Phelps win at the 2008 Beijing Olympics?");
SPOquestions.add("Who won the 2012 Olympic 100 metres mens race?");
SPOquestions.add("Which of these events are not a part of the heptathlon?");
SPOquestions.add("When was the first modern Olympics held?");
ArrayList<String> MUSquestions = new ArrayList<String>(); // adding the music questions
MUSquestions.add("'Slash' was a member of which US rock band?");
MUSquestions.add("Brian May was a member of which English rock band?");
MUSquestions.add("What is the name of the music festival held annually in the town of Boom, Belgium?");
MUSquestions.add("The rapper Tupac Shakuer '2Pac' died in which year?");
MUSquestions.add("Which of these bands headlined the 2013 Glastonbury music festival?");
MUSquestions.add("Which of these people designed the 'Les Paul' series of guitars?");
MUSquestions.add("Keith Moon was a drummer for which English rock band?");
MUSquestions.add("Kanye West has a total of how many Grammy awards?");
MUSquestions.add("Beyonce Knowles was formally a member of which US group?");
MUSquestions.add("In which US city was rapper 'Biggie Smalls' born?");
MUSquestions.add("Michael Jackson's first number one single in the UK as a solo artist was what?");
MUSquestions.add("The best selling album of all time in the UK is what?");
MUSquestions.add("The best selling album of all time in the US is what?");
MUSquestions.add("What is the artist known as 'Tiesto's real name?");
MUSquestions.add("Which of these was not a member of The Beatles?");
ArrayList<String> GENquestions = new ArrayList<String>(); // adding general knowledge questions
GENquestions.add("Who was the second President of the United States?");
GENquestions.add("The youngest son of Bob Marley was who?");
GENquestions.add("In the film '8 Mile', the character portrayed by Eminem is known as what?");
GENquestions.add("What is the capital city of New Zealand?");
GENquestions.add("What is the capital city of Australia?");
GENquestions.add("How many millilitres are there in an English pint?");
GENquestions.add("What was the biggest selling game for the PS2 worldwide?");
GENquestions.add("What is the last letter of the Greek alphabet?");
GENquestions.add("Who created the television series Futurama?");
GENquestions.add("A word which reads the same backwards as it does forwards is known as a what?");
GENquestions.add("A 'baker's dozen' consists of how many items?");
GENquestions.add("World War 1 officially occured on which date?");
GENquestions.add("'Trouble and strife' is cockney rhyming slang for what?");
GENquestions.add("Who was the last Prime Minister to hail from the labour party in the UK?");
GENquestions.add("WalMart is the parent company of which UK based supermarket chain?");
}
import java.util.*;
公开课问题{
公共静态void main(字符串[]args){
ArrayList SPOquestions=new ArrayList();//为测验添加体育问题
添加(“谁赢得了2005年一级方程式世界锦标赛?”);
添加(“哪个车队拥有最多的一级方程式赛车手头衔?”);
补充(“罗杰·费德勒在哪一年赢得了他的第一个‘大满贯’?”;
添加(“拉斐尔·纳达尔赢得了多少个‘大满贯’?);
添加(“谁在英超联赛中进球最多?”);
添加(“谁赢得了最多的足球世界杯?”);
添加(“瓦伦蒂诺·罗西拥有多少个摩托车大奖赛冠军?”);
添加(“谁是2013年摩托车大奖赛冠军?”);
添加(“谁赢得了2003年橄榄球世界杯?”);
SPOquestions.add(“在橄榄球联赛中,试一试可以获得多少分?”);
谁是史上最年轻的斯诺克世界冠军;
添加(“在斯诺克中,可能的最高休息时间是多少?”);
添加(“老虎伍兹赢了多少个大满贯?”);
在高尔夫比赛中,美国和欧洲之间的比赛叫什么;
添加(“飞镖运动员菲尔·泰勒赢得了多少次世界锦标赛?”);
添加(“一个玩家投掷三个飞镖能获得的最大可能点数是多少?”);
添加(“迈克尔·菲尔普斯在2008年北京奥运会上赢得了多少枚金牌?”);
添加(“谁赢得了2012年奥运会男子100米比赛?”);
添加(“这些事件中哪些不是七项全能的一部分?”);
添加(“第一届现代奥运会是什么时候举行的?”);
ArrayList MUSquestions=new ArrayList();//添加音乐问题
加上(“'Slash'是哪个美国摇滚乐队的成员?”);
添加(“布莱恩·梅是哪个英国摇滚乐队的成员?”);
MUSquestions.add(“每年在比利时布姆镇举行的音乐节叫什么名字?”);
添加(“说唱歌手Tupac Shakuer'2Pac'死于哪一年?”);
MUSquestions.add(“2013年格拉斯顿伯里音乐节的主唱是哪支乐队?”);
添加(“这些人中谁设计了‘Les Paul’系列吉他?”);
加上(“基思·穆恩是哪个英国摇滚乐队的鼓手?”);
加上(“KanyeWest总共获得了多少格莱美奖?”);
MUSquestions.add(“碧昂丝·诺尔斯正式成为哪个美国团体的成员?”);
MUSquestions.add(“说唱歌手‘Biggie Smalls’出生于美国哪个城市?”);
MUSquestions.add(“迈克尔·杰克逊作为独唱歌手在英国的第一首单曲是什么?”);
添加(“英国有史以来最畅销的专辑是什么?”);
添加(“美国有史以来最畅销的专辑是什么?”);
添加(“艺术家的真实姓名是什么?”);
MUSquestions.add(“其中哪一个不是披头士的成员?”);
ArrayList GENquestions=新建ArrayList();//添加一般知识问题
GENquestions.add(“谁是美国第二任总统?”);
加上(“鲍勃·马利最小的儿子是谁?”);
加上(“在电影《8英里》中,阿姆扮演的角色被称为什么?”;
GENquestions.add(“新西兰的首都是什么?”);
GENquestions.add(“澳大利亚的首都是什么?”);
加上(“一英式品脱有多少毫升?”);
GENquestions.add(“全球PS2最畅销的游戏是什么?”);
添加(“希腊字母表的最后一个字母是什么?”);
GENquestions.add(“谁创造了电视连续剧Futurama?”);
添加(“一个向后读和向前读一样的单词被称为what?”);
GENquestions.add(“一个‘面包师的一打’由多少个项目组成?”);
GENquestions.add(“第一次世界大战正式发生在哪一天?”);
加上“‘麻烦和冲突’是伦敦的押韵俚语,意思是什么?”;
GENquestions.add(“谁是英国最后一位来自工党的首相?”);
GENquestions.add(“沃尔玛是哪家英国连锁超市的母公司?”);
}
}
你得原谅我,我有点生疏了。我应该如何对代码进行编程,使其对其他任何东西以及后续的getter方法都不可见。。。我知道它应该在一个文本文件中,我曾试图实现它,但一开始无法实现,我将再次尝试,希望与您联系guidance@user3455584:你需要澄清一下