I wtiten this is
java class
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FlashTest
{
JFrame frame1;
JTextArea txtA, txtQ;
JButton btnShowAns, btnNext;
JPanel panel1;
JScrollPane scroller1, scroller2;
ArrayList<
String> strArray = new ArrayList<String>();
static int count = 0;
static int i = 0;
void buildGUI()
{
frame1 = new JFrame("Test Your Knowledge");
txtQ = new JTextArea(20, 30);
txtA = new JTextArea(20, 30);
txtQ.setLineWrap(true);
txtA.setLineWrap(true);
txtA.setVisible(false);
scroller1 = new JScrollPane(txtQ);
scroller2 = new JScrollPane(txtA);
//scroller1.add(txtQ);
//scroller2.add(txtA);
scroller1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroller2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
btnShowAns = new JButton("Show Answer");
btnNext = new JButton("Next Question");
panel1 = new JPanel();
//panel1.add(txtQ);
//panel1.add(txtA);
panel1.add(scroller1);
panel1.add(scroller2);
panel1.add(btnShowAns);
panel1.add(btnNext);
frame1.getContentPane().add(panel1);
frame1.setSize(800, 570);
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnShowAns.addActionListener(new ShowAnsListener());
btnNext.addActionListener(new NextListener());
try
{
BufferedReader br = new BufferedReader(new FileReader("FlashCardsData.ser"));
String line = null;
while((line = br.readLine())!=null)
{
String[] splitStrings = line.split("/");
for(String elt:splitStrings)
{
strArray.add(elt);
}
}
}
catch(Exception e)
{
System.out.println("Exception in buildGUI: " + e);
}
fillText();
}
void fillText()
{
i++;
if(i<(strArray.size()-2))
{
txtQ.setText((String) strArray.get(count));
txtA.setText((String) strArray.get(++count));
count++;
}
else
{
System.out.println("Sorry! No more data here!");
JOptionPane.showMessageDialog(null, "This is the last question.");
//JOptionPane.showOptionDialog(null, "Sorry!", "Create New");
}
}
void toggleButton()
{
if((btnShowAns.getText()).equals("Show Answer"))
{
btnShowAns.setText("Hide Answer");
txtA.setVisible(true);
}
else
{
btnShowAns.setText("Show Answer");
txtA.setVisible(false);
}
}
class ShowAnsListener implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
toggleButton();
}
}
class NextListener implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{
toggleButton();
fillText();
}
catch(Exception e)
{
System.out.println("Exception in NextListener: " + e);
JOptionPane.showMessageDialog(null, "This is the last question.");
}
}
}
public static void main(String[] str)
{
FlashTest ft = new FlashTest();
ft.buildGUI();
}
}