| | |
how to make gui game
![]() |
•
•
Join Date: May 2009
Posts: 4
Reputation:
Solved Threads: 0
I have some code written in Java, but I have no idea how to make this into a GUI based game. The questions and answers are in a text file. Please help. Here is part of the code:
Please help!!
public class QnA
{
//index of correct answer when calling the getAnswer() method:
public static final int RIGHT_ANSWER = 5;
private Vector question = new Vector ();//contains the questions
private Vector answer1 = new Vector ();//first possible answer
private Vector answer2 = new Vector ();//second possible answer
private Vector answer3 = new Vector ();//third possible answer
private Vector answer4 = new Vector ();//fourth possible answer
private Vector right = new Vector ();//(index)correct answer
public QnA (String UGGR)
{
String s;
/*flag rot determine what is to be read next;
0 - question
1 - first answer
2 - second answer
3 - third answer
4 - fourth answer
5 - correct answer */
int readNow = 0;
try
{
FileReader fsource = new FileReader (UGGR);
BufferedReader bsource = new BufferedReader (fsource);
while((s = bsource.readLine()) != null)
{
s = s.trim(); //remove spaces from both ends of a string
if (s.length() !=0) //ignores empty lines
if (readNow == 0)
{
question.addElement(s);
readNow++;
}
else if (readNow == 1)
{
answer1.addElement(s);
readNow++;
}
else if (readNow == 2)
{
answer2.addElement(s);
readNow++;
}
else if (readNow == 3)
{
answer3.addElement(s);
readNow++;
}
else if (readNow == 4)
{
answer4.addElement(s);
readNow++;
}
else if (readNow == 5)
{
right.addElement(s);
readNow = 0;
}
}
bsource.close();
fsource.close();
if (readNow !=0)
{
System.err.println("File" + "UGGR.txt" + ", last question is incomplete!");
System.exit(1);
}
}
catch (Exception e)
{
System.err.println("Error loading questions: " + e);
System.exit(1);
}
if(getNumberOfQuestions() < 1)
{
System.err.println("No questions loaded!");
System.exit(1);
}
}
public int getNumberOfQuestions()
{
return question.size();
}
public String getQuestion(int index)
{
try
{
return (String) question.get(index);
}
catch (ArrayIndexOutOfBoundsException e)
{
return "NO QUESTION";
}
}
public String getAnswer(int index, int qNumber)
{
try
{
switch(qNumber)
{
case 1:
return (String)answer1.get(index);
case 2:
return (String)answer2.get(index);
case 3:
return (String)answer3.get(index);
case 4:
return (String)answer4.get(index);
case 5:
return (String)right.get(index);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
}
return "NO ANSWER";
}
} Last edited by Ancient Dragon; May 29th, 2009 at 9:46 am. Reason: add code tags
If you want to make an applet or application style gui, try awt, or more preferably swing. Swing is the library used to do most guis in java
92% of all statistics are made up on the spot.
If you found a post helpful, please click the "give XXX reputation" link, to show your appreciation to those who helped you. Thanks! :D
If you found a post helpful, please click the "give XXX reputation" link, to show your appreciation to those who helped you. Thanks! :D
![]() |
Similar Threads
- How do I make a GUI in C++ (C++)
- how do i make a web game (Site Layout and Usability)
- maze game (C++)
- Contribute to make an RTS game in DirectX (not tutorial) (Game Development)
Other Threads in the Game Development Forum
- Previous Thread: Can you use a Card Layout on Game Panels?
- Next Thread: Making a 3D engine from scratch
| Thread Tools | Search this Thread |
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamer games gaming gauntanamo government idaho in-gameadvertisement intellectualproperty laracroft live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn naked news nintendo obama opengl palin physics pirate playstation politics projection ps3 rpg search selection software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360





