CrorepatiView.java.
/*
* Created By...
* Santanu Kar
*/
package crorepati;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.sql.*;
import java.util.*;
import java.awt.Color;
/**
* The application's main frame.
*/
public class CrorepatiView extends FrameView {
public CrorepatiView(SingleFrameApplication app) {
super(app);
initComponents();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
setQuestion();
}
void createDatabase(){
try{
// load the sqlite-JDBC driver using the current class loader
Class.forName("org.sqlite.JDBC");
Connection connection = null;
connection = DriverManager.getConnection("jdbc:sqlite:game.db");
Statement statement = connection.createStatement();
try
{
statement.setQueryTimeout(30); // set timeout to 30 sec.
rs = statement.executeQuery("select * from questions");
while(rs.next())
{
// read the result set
System.out.println("id = " + rs.getInt("id"));
System.out.println("question = " + rs.getString("question"));
System.out.println("ans1 = " + rs.getString("ans1"));
System.out.println("ans2 = " + rs.getString("ans2"));
System.out.println("ans3 = " + rs.getString("ans3"));
System.out.println("ans4 = " + rs.getString("ans4"));
System.out.println("answer = " + rs.getInt("answer"));
}
}
catch(SQLException e)
{
// if the error message is "out of memory",
// it probably means no database file is found
//System.err.println(e.getMessage());
try{
statement = connection.createStatement();
statement.executeUpdate("create table questions (id integer, question string, ans1 string, ans2 string, ans3 string, ans4 string, answer integer)");
statement.executeUpdate("insert into questions values(1, 'Antyodaya scheme is meant to help the', 'Muslims', 'Minorities', 'Poorest of the poor section of the society', 'Harijans', 3)");
statement.executeUpdate("insert into questions values(2, 'Name the Indian telecom service company which had acquired US firm WPCS International?', 'BSNL', 'MTNL', 'Tata Teleservices', 'Kavvery Telecom', 4)");
}
catch(Exception ex){
ex.printStackTrace();
}
}
finally
{
try
{
if(connection != null)
connection.close();
}
catch(SQLException e)
{
// connection close failed.
System.err.println(e);
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
void setQuestion(){
System.out.println("setQuention() called");
setOtherEnable();
LTimer.setText("30");
time_count=30;
ans_clicked=true;
sc = new StopClock(this);
Thread th = new Thread(sc);
th.start();
try{
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:game.db");
if(conn != null) {
q_id=showRandomInteger(1, 2, randomGenerator);
System.out.println("Q-ID is " + q_id);
String query = "select * from questions where id=?";
ps = conn.prepareStatement(query);
ps.setInt(1,q_id);
rs = ps.executeQuery();
if(rs.next()){
System.out.println("!!!!!!!!!!!!!!");
LQuestion.setText(rs.getString(2));
BAns1.setText(rs.getString(3));
BAns2.setText(rs.getString(4));
BAns3.setText(rs.getString(5));
BAns4.setText(rs.getString(6));
correct_ans=rs.getInt(7);
}
else {
System.out.println("**************");
}
conn.close();
}
else {
System.out.println("Connection problem, please try again");
}
}
catch(Exception ex){
ex.printStackTrace();
try{
Statement statement = conn.createStatement();
statement = conn.createStatement();
statement.executeUpdate("create table questions (id integer, question string, ans1 string, ans2 string, ans3 string, ans4 string, answer integer)");
statement.executeUpdate("insert into questions values(1, 'Antyodaya scheme is meant to help the', 'Muslims', 'Minorities', 'Poorest of the poor section of the society', 'Harijans', 3)");
statement.executeUpdate("insert into questions values(2, 'Name the Indian telecom service company which had acquired US firm WPCS International?', 'BSNL', 'MTNL', 'Tata Teleservices', 'Kavvery Telecom', 4)");
}
catch(Exception exx){
exx.printStackTrace();
}
}
//startTimer();
}
void getAnswer(int ans){
System.out.println("\ngetAnswer(int ans) called.");
ans_clicked=false;
System.out.println("######ans_clicked:"+ans_clicked);
setOtherDisable();
setButtonDisable();
//coloring green to correct ans
if(correct_ans==1){
BNext.setEnabled(true);
BAns1.setBackground(new Color(0,102,51));
BAns1.setForeground(new Color(0,102,51));
}
else if(correct_ans==2){
BNext.setEnabled(true);
BAns2.setBackground(new Color(0,102,51));
BAns2.setForeground(new Color(0,102,51));
}
else if(correct_ans==3){
BNext.setEnabled(true);
BAns3.setBackground(new Color(0,102,51));
BAns3.setForeground(new Color(0,102,51));
}
else{
BNext.setEnabled(true);
BAns4.setBackground(new Color(0,102,51));
BAns4.setForeground(new Color(0,102,51));
}
//coloring red to incorrect ans
if(correct_ans!=ans){
System.out.println("Wrong ans");
if(ans==1){
BNext.setEnabled(false);
BAns1.setBackground(new Color(255,0,0));
BAns1.setForeground(new Color(255,0,0));
}
else if(ans==2){
BNext.setEnabled(false);
BAns2.setBackground(new Color(255,0,0));
BAns2.setForeground(new Color(255,0,0));
}
else if(ans==3){
BNext.setEnabled(false);
BAns3.setBackground(new Color(255,0,0));
BAns3.setForeground(new Color(255,0,0));
}
else{
BNext.setEnabled(false);
BAns4.setBackground(new Color(255,0,0));
BAns4.setForeground(new Color(255,0,0));
}
}
else{
System.out.println("Correct ans");
//BNext.setEnabled(true);
}
}
private static int showRandomInteger(int aStart, int aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Generated : " + randomNumber);
return randomNumber;
}
private static void log(String aMessage){
System.out.println(aMessage);
}
void setHelpDisable(){
if(!BFifty_fifty.isVisible() && !BBar_chart.isVisible())
LEnd_help.setVisible(true);
}
void setButtonDisable(){
BAns1.setEnabled(false);
BAns2.setEnabled(false);
BAns3.setEnabled(false);
BAns4.setEnabled(false);
//ans_clicked=false;
}
void setOtherDisable(){
BNext.setEnabled(true);
BFifty_fifty.setEnabled(false);
BBar_chart.setEnabled(false);
}
void setOtherEnable(){
BNext.setEnabled(false);
BFifty_fifty.setEnabled(true);
BBar_chart.setEnabled(true);
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = CrorepatiApp.getApplication().getMainFrame();
aboutBox = new CrorepatiAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
CrorepatiApp.getApplication().show(aboutBox);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
mainPanel = new javax.swing.JPanel();
LWelcome = new javax.swing.JLabel();
LImg = new javax.swing.JLabel();
LHelp = new javax.swing.JLabel();
BFifty_fifty = new javax.swing.JButton();
BBar_chart = new javax.swing.JButton();
LTimer = new javax.swing.JLabel();
LQuestion = new javax.swing.JLabel();
BAns1 = new javax.swing.JButton();
BAns2 = new javax.swing.JButton();
BAns3 = new javax.swing.JButton();
BAns4 = new javax.swing.JButton();
BQuit = new javax.swing.JButton();
BNext = new javax.swing.JButton();
LRs10 = new javax.swing.JLabel();
LRs9 = new javax.swing.JLabel();
LRs8 = new javax.swing.JLabel();
LRs7 = new javax.swing.JLabel();
LRs6 = new javax.swing.JLabel();
LRs5 = new javax.swing.JLabel();
LRs4 = new javax.swing.JLabel();
LRs3 = new javax.swing.JLabel();
LRs2 = new javax.swing.JLabel();
LRs1 = new javax.swing.JLabel();
LEnd_help = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(crorepati.CrorepatiApp.class).getContext().getResourceMap(CrorepatiView.class);
mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
mainPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))));
mainPanel.setName("mainPanel"); // NOI18N
LWelcome.setFont(resourceMap.getFont("LWelcome.font")); // NOI18N
LWelcome.setForeground(resourceMap.getColor("LWelcome.foreground")); // NOI18N
LWelcome.setText(resourceMap.getString("LWelcome.text")); // NOI18N
LWelcome.setName("LWelcome"); // NOI18N
LImg.setBackground(resourceMap.getColor("LImg.background")); // NOI18N
LImg.setIcon(resourceMap.getIcon("LImg.icon")); // NOI18N
LImg.setText(resourceMap.getString("LImg.text")); // NOI18N
LImg.setName("LImg"); // NOI18N
LHelp.setFont(resourceMap.getFont("LHelp.font")); // NOI18N
LHelp.setForeground(resourceMap.getColor("LHelp.foreground")); // NOI18N
LHelp.setText(resourceMap.getString("LHelp.text")); // NOI18N
LHelp.setName("LHelp"); // NOI18N
BFifty_fifty.setBackground(resourceMap.getColor("BFifty_fifty.background")); // NOI18N
BFifty_fifty.setForeground(resourceMap.getColor("BFifty_fifty.foreground")); // NOI18N
BFifty_fifty.setIcon(resourceMap.getIcon("BFifty_fifty.icon")); // NOI18N
BFifty_fifty.setText(resourceMap.getString("BFifty_fifty.text")); // NOI18N
BFifty_fifty.setName("BFifty_fifty"); // NOI18N
BFifty_fifty.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BFifty_fiftyActionPerformed(evt);
}
});
BBar_chart.setBackground(resourceMap.getColor("BBar_chart.background")); // NOI18N
BBar_chart.setIcon(resourceMap.getIcon("BBar_chart.icon")); // NOI18N
BBar_chart.setText(resourceMap.getString("BBar_chart.text")); // NOI18N
BBar_chart.setName("BBar_chart"); // NOI18N
BBar_chart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BBar_chartActionPerformed(evt);
}
});
LTimer.setText(resourceMap.getString("LTimer.text")); // NOI18N
LTimer.setName("LTimer"); // NOI18N
LQuestion.setText(resourceMap.getString("LQuestion.text")); // NOI18N
LQuestion.setName("LQuestion"); // NOI18N
BAns1.setText(resourceMap.getString("BAns1.text")); // NOI18N
BAns1.setName("BAns1"); // NOI18N
BAns1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BAns1ActionPerformed(evt);
}
});
BAns2.setText(resourceMap.getString("BAns2.text")); // NOI18N
BAns2.setName("BAns2"); // NOI18N
BAns2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BAns2ActionPerformed(evt);
}
});
BAns3.setText(resourceMap.getString("BAns3.text")); // NOI18N
BAns3.setName("BAns3"); // NOI18N
BAns3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BAns3ActionPerformed(evt);
}
});
BAns4.setText(resourceMap.getString("BAns4.text")); // NOI18N
BAns4.setName("BAns4"); // NOI18N
BAns4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BAns4ActionPerformed(evt);
}
});
BQuit.setBackground(resourceMap.getColor("BQuit.background")); // NOI18N
BQuit.setFont(resourceMap.getFont("BQuit.font")); // NOI18N
BQuit.setText(resourceMap.getString("BQuit.text")); // NOI18N
BQuit.setName("BQuit"); // NOI18N
BQuit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BQuitActionPerformed(evt);
}
});
BNext.setBackground(resourceMap.getColor("BNext.background")); // NOI18N
BNext.setFont(resourceMap.getFont("BNext.font")); // NOI18N
BNext.setText(resourceMap.getString("BNext.text")); // NOI18N
BNext.setEnabled(false);
BNext.setName("BNext"); // NOI18N
BNext.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BNextActionPerformed(evt);
}
});
LRs10.setFont(resourceMap.getFont("LRs10.font")); // NOI18N
LRs10.setForeground(resourceMap.getColor("LRs10.foreground")); // NOI18N
LRs10.setText(resourceMap.getString("LRs10.text")); // NOI18N
LRs10.setName("LRs10"); // NOI18N
LRs9.setFont(resourceMap.getFont("LRs9.font")); // NOI18N
LRs9.setForeground(resourceMap.getColor("LRs9.foreground")); // NOI18N
LRs9.setText(resourceMap.getString("LRs9.text")); // NOI18N
LRs9.setName("LRs9"); // NOI18N
LRs8.setFont(resourceMap.getFont("LRs8.font")); // NOI18N
LRs8.setForeground(resourceMap.getColor("LRs9.foreground")); // NOI18N
LRs8.setText(resourceMap.getString("LRs8.text")); // NOI18N
LRs8.setName("LRs8"); // NOI18N
LRs7.setFont(resourceMap.getFont("LRs7.font")); // NOI18N
LRs7.setForeground(resourceMap.getColor("LRs7.foreground")); // NOI18N
LRs7.setText(resourceMap.getString("LRs7.text")); // NOI18N
LRs7.setName("LRs7"); // NOI18N
LRs6.setFont(resourceMap.getFont("LRs6.font")); // NOI18N
LRs6.setForeground(resourceMap.getColor("LRs6.foreground")); // NOI18N
LRs6.setText(resourceMap.getString("LRs6.text")); // NOI18N
LRs6.setName("LRs6"); // NOI18N
LRs5.setFont(resourceMap.getFont("LRs5.font")); // NOI18N
LRs5.setForeground(resourceMap.getColor("LRs5.foreground")); // NOI18N
LRs5.setText(resourceMap.getString("LRs5.text")); // NOI18N
LRs5.setName("LRs5"); // NOI18N
LRs4.setFont(resourceMap.getFont("LRs4.font")); // NOI18N
LRs4.setForeground(resourceMap.getColor("LRs2.foreground")); // NOI18N
LRs4.setText(resourceMap.getString("LRs4.text")); // NOI18N
LRs4.setName("LRs4"); // NOI18N
LRs3.setFont(resourceMap.getFont("LRs3.font")); // NOI18N
LRs3.setForeground(resourceMap.getColor("LRs2.foreground")); // NOI18N
LRs3.setText(resourceMap.getString("LRs3.text")); // NOI18N
LRs3.setName("LRs3"); // NOI18N
LRs2.setFont(resourceMap.getFont("LRs2.font")); // NOI18N
LRs2.setForeground(resourceMap.getColor("LRs2.foreground")); // NOI18N
LRs2.setText(resourceMap.getString("LRs2.text")); // NOI18N
LRs2.setName("LRs2"); // NOI18N
LRs1.setFont(resourceMap.getFont("LRs1.font")); // NOI18N
LRs1.setForeground(resourceMap.getColor("LRs1.foreground")); // NOI18N
LRs1.setText(resourceMap.getString("LRs1.text")); // NOI18N
LRs1.setName("LRs1"); // NOI18N
LEnd_help.setFont(resourceMap.getFont("LEnd_help.font")); // NOI18N
LEnd_help.setForeground(resourceMap.getColor("LEnd_help.foreground")); // NOI18N
LEnd_help.setText(resourceMap.getString("LEnd_help.text")); // NOI18N
LEnd_help.setVisible(false);
LEnd_help.setName("LEnd_help"); // NOI18N
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(LQuestion, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
.addContainerGap())
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(BFifty_fifty)
.addGap(18, 18, 18)
.addComponent(BBar_chart))
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(LEnd_help, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(LHelp)))
.addGap(39, 39, 39)
.addComponent(LImg))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(316, 316, 316)
.addComponent(LTimer)))
.addGap(110, 110, 110)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(LRs10)
.addGap(57, 57, 57))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(LRs3)
.addComponent(LRs2)
.addComponent(LRs1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(LRs4)
.addComponent(LRs6)
.addComponent(LRs5)
.addComponent(LRs9)
.addComponent(LRs8)
.addComponent(LRs7))
.addContainerGap())))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(LWelcome)
.addContainerGap(159, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(BAns3, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
.addComponent(BAns1, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(BAns4, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
.addComponent(BAns2, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addGap(37, 37, 37))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addContainerGap(415, Short.MAX_VALUE)
.addComponent(BQuit, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(BNext, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(84, 84, 84))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(LWelcome)
.addGap(11, 11, 11)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(LHelp)
.addGap(18, 18, 18)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(BFifty_fifty, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BBar_chart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LEnd_help))
.addComponent(LImg))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LTimer))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(LRs10)
.addGap(18, 18, 18)
.addComponent(LRs9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs7)
.addGap(18, 18, 18)
.addComponent(LRs6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs5)
.addGap(26, 26, 26)
.addComponent(LRs4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LRs1)))
.addGap(6, 6, 6)
.addComponent(LQuestion)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BAns1)
.addComponent(BAns2))
.addGap(18, 18, 18)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BAns3)
.addComponent(BAns4))
.addGap(27, 27, 27)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BQuit)
.addComponent(BNext))
.addGap(58, 58, 58))
);
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(crorepati.CrorepatiApp.class).getContext().getActionMap(CrorepatiView.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(statusMessageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 510, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusMessageLabel)
.addComponent(statusAnimationLabel)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void BAns1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBAns1_actionPerformed(ActionEvent e) called.");
getAnswer(1);
}
private void BAns2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBAns2_actionPerformed(ActionEvent e) called.");
getAnswer(2);
}
private void BAns3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBAns3_actionPerformed(ActionEvent e) called.");
getAnswer(3);
}
private void BAns4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBAns4_actionPerformed(ActionEvent e) called.");
getAnswer(4);
}
private void BQuitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBQuit_actionPerformed(ActionEvent e) called.");
this.getFrame().setVisible(false);
System.out.println("2222222222222");
new QuitGame();
System.out.println("3333333333333");
}
private void BNextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBNext_actionPerformed(ActionEvent e) called.");
BAns1.setEnabled(true);
BAns2.setEnabled(true);
BAns3.setEnabled(true);
BAns4.setEnabled(true);
BAns1.setVisible(true);
BAns2.setVisible(true);
BAns3.setVisible(true);
BAns4.setVisible(true);
setHelpDisable();
BAns1.setBackground(new Color(240,240,240));
BAns1.setForeground(new Color(0,0,0));
BAns2.setBackground(new Color(240,240,240));
BAns2.setForeground(new Color(0,0,0));
BAns3.setBackground(new Color(240,240,240));
BAns3.setForeground(new Color(0,0,0));
BAns4.setBackground(new Color(240,240,240));
BAns4.setForeground(new Color(0,0,0));
BNext.setEnabled(true);
setQuestion();
}
private void BFifty_fiftyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
BFifty_fifty.setVisible(false);
System.out.println("\nBFifty_fifty_actionPerformed(ActionEvent e) called.");
if(correct_ans==1){
BAns2.setVisible(false);
BAns3.setVisible(false);
}
else if(correct_ans==2){
BAns1.setVisible(false);
BAns3.setVisible(false);
}
else if(correct_ans==3){
BAns2.setVisible(false);
BAns4.setVisible(false);
}
else if(correct_ans==4){
BAns2.setVisible(false);
BAns3.setVisible(false);
}
}
private void BBar_chartActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println("\nBBar_chart_actionPerformed(ActionEvent e) called.");
BBar_chart.setVisible(false);
if(correct_ans==1){
BAns2.setVisible(false);
BAns3.setVisible(false);
BAns4.setVisible(false);
}
else if(correct_ans==2){
BAns1.setVisible(false);
BAns3.setVisible(false);
BAns4.setVisible(false);
}
else if(correct_ans==3){
BAns1.setVisible(false);
BAns2.setVisible(false);
BAns4.setVisible(false);
}
else if(correct_ans==4){
BAns1.setVisible(false);
BAns2.setVisible(false);
BAns3.setVisible(false);
}
}
// Variables declaration - do not modify
private javax.swing.JButton BAns1;
private javax.swing.JButton BAns2;
private javax.swing.JButton BAns3;
private javax.swing.JButton BAns4;
javax.swing.JButton BBar_chart;
javax.swing.JButton BFifty_fifty;
javax.swing.JButton BNext;
private javax.swing.JButton BQuit;
javax.swing.JLabel LEnd_help;
private javax.swing.JLabel LHelp;
private javax.swing.JLabel LImg;
private javax.swing.JLabel LQuestion;
private javax.swing.JLabel LRs1;
private javax.swing.JLabel LRs10;
private javax.swing.JLabel LRs2;
private javax.swing.JLabel LRs3;
private javax.swing.JLabel LRs4;
private javax.swing.JLabel LRs5;
private javax.swing.JLabel LRs6;
private javax.swing.JLabel LRs7;
private javax.swing.JLabel LRs8;
private javax.swing.JLabel LRs9;
javax.swing.JLabel LTimer;
private javax.swing.JLabel LWelcome;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration
Connection conn = null;
PreparedStatement ps;
ResultSet rs;
int q_id=0;
int correct_ans=0;
int time_count=30;
boolean ans_clicked=true;
StopClock sc;
Random randomGenerator = new Random();
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
}
class StopClock extends Thread{
CrorepatiView c;
StopClock(CrorepatiView c){
this.c=c;
}
public void run(){
while(c.time_count>0 && c.ans_clicked){
//System.out.println("************ans_clicked:"+c.ans_clicked);
try{
this.sleep(1000);
}
catch(Exception e){
e.printStackTrace();
}
c.time_count--;
c.LTimer.setText(c.time_count+"");
}
c.setButtonDisable();
if(c.time_count==0){
c.setOtherDisable();
c.BNext.setEnabled(false);
}
}
}
can you show us the database records too?
ReplyDelete