rendered paste body#
import java.awt.*;
#
import java.awt.event.*;
#
import javax.swing.*;
#
#
public class NTBApplet extends JApplet
#
implements ActionListener
#
{
#
private Interface myInterface = new Interface();
#
private String myQuestion = "";
#
private String myAnswer = "";
#
private int myAnswerPlace = 0;
#
private int myQuestionPlace = 0;
#
private JButton button1, button2, button3;
#
private Font textFont = new Font("Verdana",Font.BOLD,12);
#
#
#
public void init()
#
{
#
button1 = new JButton("Next Question");
#
button1.setToolTipText("Next Question");
#
button1.addActionListener(this);
#
#
button2 = new JButton("Show Answer");
#
button2.setToolTipText("Show Answer");
#
button2.addActionListener(this);
#
button2.setEnabled(false);
#
#
button3 = new JButton("Input Questions");
#
button3.setToolTipText("Input Questions");
#
button3.addActionListener(this);
#
#
JPanel panel = new JPanel();
#
panel.add(button1);
#
panel.add(button2);
#
#
JPanel panel2 = new JPanel();
#
panel.add(button3);
#
#
Container c = getContentPane();
#
c.setBackground(Color.white);
#
c.add(panel, BorderLayout.SOUTH);
#
c.add(panel2, BorderLayout.EAST);
#
}
#
#
/**
#
* Processes button events
#
*/
#
public void actionPerformed(ActionEvent e)
#
{
#
JButton button = (JButton)e.getSource();
#
#
if (myInterface.getStack().size() == 0) //if there are no more questions/answers make a new interface.
#
{
#
myInterface = new Interface();
#
myAnswerPlace = 0;
#
myQuestionPlace = 0;
#
JOptionPane.showMessageDialog(this, "All questions have been used and will now be reused.", "New Questions", JOptionPane.INFORMATION_MESSAGE);
#
myQuestion = "";
#
myAnswer = "";
#
}
#
#
else if (myInterface.getStack().size() > 0)
#
{
#
if (button == button1)
#
{
#
myQuestion = myInterface.getQuestion();
#
#
myAnswer = "";
#
button1.setEnabled(false);
#
myQuestionPlace++;
#
}
#
else if (button == button2)
#
{
#
myAnswer = myInterface.getAnswer();
#
button1.setEnabled(true);
#
myAnswerPlace++;
#
}
#
else if (button == button3)
#
{
#
String inputQuestion = JOptionPane.showInputDialog("Enter Question:");
#
String inputAnswer = JOptionPane.showInputDialog("Enter Answer:");
#
myInterface.enterQuestion(inputQuestion);
#
myInterface.enterAnswer(inputAnswer);
#
myInterface = new Interface();
#
JOptionPane.showMessageDialog(this, "A new round will start.", "New Questions", JOptionPane.INFORMATION_MESSAGE);
#
#
}
#
#
if ( myQuestionPlace > myAnswerPlace)
#
button2.setEnabled(true);
#
else
#
button2.setEnabled(false);
#
}
#
#
#
repaint();
#
}
#
#
public void paint(Graphics g)
#
{
#
super.paint(g);
#
//g.setFont(textFont);
#
g.drawString("Question:", 10, 25);
#
g.drawLine(10, 30, 680, 30);
#
g.drawString(myQuestion, 10, 45);
#
#
g.drawString("Answer:", 10, 65);
#
g.drawLine(10, 70, 680, 70);
#
g.drawString(myAnswer, 10, 85);
#
}
#