• Post Reply Bookmark Topic Watch Topic
  • New Topic

java io/reading from Disk file using RandomAccessFile class  RSS feed

 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintStream;
import javax.swing.JPanel;
import java.lang.Thread;
import javax.swing.JFrame;
import javax.swing.JLabel.*;
import javax.swing.JButton.*;
import javax.swing.JDialog;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.Timer;
import javax.swing.border.*;
import java.security.*;
import javax.swing.text.*;
import java.lang.String.*;
import java.awt.AWTEvent.*;


public class JavaExam extends JFrame {


JLabel time;
JButton first,previous,next,last,exit;
private JTextArea question;
JRadioButton ans1,ans2,ans3,ans4;


JLabel hh1 = new JLabel();
JLabel hh2 = new JLabel();
JLabel mm1 = new JLabel();

JLabel mm2= new JLabel();

JLabel ss1 = new JLabel();
JLabel ss2 = new JLabel();
JLabel colon1 = new JLabel();
JLabel colon2 = new JLabel();
TitledBorder tb;
JFrame je=new JFrame();
String squestion,sca,sans1,sans2,sans3,sans4,subjectcode;

int questionNos[]=new int[4];
int qNo;
int i=0;
int totalq=4;
String subjects[]=new String[7];
String ssubjectcode[]=new String[7];
{
for(int i=0;i<6;++i){
ssubjectcode[i]=" "+i;
}
}


String questions[]=new String[4];
{
for (int i=0;i<4;i++)
questions[i]=" "+i;
}

String answers[][]=new String[4][4];
{
for(int i=0; i<4; ++i)
for(int j=0; j<4; ++j)
answers[i][j]=" " +i+j;
}
int correctAnswers[]=new int[4];
int correctFinalAnswers[]=new int[4];
int userChoices[]=new int[4];


RandomAccessFile rafQuestions;
JPanel centerPanel;
String email=new String();
String candidateName=new String();

JavaExam app;

public static void main(String[] args) throws FileNotFoundException,IOException
{
JavaExam app=new JavaExam();


}

public JavaExam()throws FileNotFoundException,IOException
{
super("JavaExam");
this.email=email;
this.candidateName=candidateName;
this.subjects=new String[0];
JFrame je = new JFrame();
je.addWindowListener(new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{System.exit(0);}
});
SettingLayout();
pack();
rafQuestions=new RandomAccessFile("ansquestions.bin","rw");
addWindowListener(new WindowEventHandler());
Dimension d;
d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((d.width-getBounds().width)/2,(d.height-getBounds().height)/2);
setVisible(true);
setResizable(false);

}


public void PopulateQuestionsArray() throws FileNotFoundException,IOException
{



RandomAccessFile rafQuestions= new RandomAccessFile("ansquestions.bin","r");



try
{
rafQuestions.seek(0);
while(rafQuestions.getFilePointer() <rafQuestions.length())
{

qNo=rafQuestions.readInt();
squestion=rafQuestions.readUTF();
subjectcode=rafQuestions.readUTF();
sca=rafQuestions.readUTF();
sans1=rafQuestions.readUTF();
sans2=rafQuestions.readUTF();
sans3=rafQuestions.readUTF();
sans4=rafQuestions.readUTF();
i++;


}

totalq=i;

questions=new String[i];
answers=new String[i][4];
userChoices = new int[4];
ssubjectcode=new String[i];
correctAnswers =new int[i];

rafQuestions.seek(0);
i=0;
while (rafQuestions.getFilePointer() <rafQuestions.length())
{


rafQuestions.readInt();
questions[i]=new String(rafQuestions.readUTF());
ssubjectcode[i]=rafQuestions.readUTF();
ssubjectcode[i]=ssubjectcode[i].trim();
correctAnswers[i] =Integer.parseInt(rafQuestions.readUTF());

answers[i][0]=new String(rafQuestions.readUTF());
answers[i][1]=new String (rafQuestions.readUTF());
answers[i][2]=new String(rafQuestions.readUTF());
answers[i][3]=new String(rafQuestions.readUTF());

i++;

}


totalq =i;
i=0;
questionNos =new int[4];

outer:
while(i<=3)
{
int num = (int)(Math.random()*1000);
for(int j=0;j<questionNos.length; j++)
{
if(num == questionNos[j])
{
continue outer;
}
}

if(num < totalq)
{
questionNos[i]=num;
correctFinalAnswers[i]=correctAnswers[num];
i++;
}

}

totalq =4;

i=0;

}

catch(Exception e)
{
System.out.println(e.getMessage());
}
}



public void SettingLayout() throws FileNotFoundException,IOException
{
PopulateQuestionsArray();
JPanel top,top1,top2;
JPanel center;
JPanel bottom,bottom1,bottom2;
//instantiating panels
top = new JPanel(new BorderLayout());
//GridLayout(1,1));
// top1=new JPanel();

top1 = new JPanel(new BorderLayout());
top1.setBackground(Color.orange);
// top2=new JPanel(new GridLayout(1,1));
top2 = new JPanel(new GridLayout(1,8,2,2));
top2.setBackground(Color.orange);


centerPanel = new JPanel(new BorderLayout());
center= new JPanel();
tb= new TitledBorder("Question 1/4");
tb.setTitle("Question 1/4 ["+ssubjectcode[0]+"]");
// tb.setTitle("questions "+new Integer(i+1).toString()+"/4" +"[" + ssubjectcode[i]+ "]");
centerPanel.setBorder(tb);
bottom =new JPanel(new GridLayout(1,2));

//to do for top panel
JLabel cscImage = new JLabel(new ImageIcon("tmh.gif"));
top1.add(cscImage);
//instantiating the timer thread and starting the timer
time = new JLabel();
TimerThread t= new TimerThread();
t.start();


top2.add(hh1);
top2.add(hh2);
top2.add(colon1);
top2.add(mm1);
top2.add(mm2);
top2.add(colon2);
top2.add(ss1);
top2.add(ss2);
top.add("West",top1);
top.add("East",top2);


// to do for center pane
bottom1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
bottom2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
bottom.add(bottom1);
bottom.add(bottom2);
//instantiating buttons
first = new JButton("First");
first.addActionListener(new FirstHandler(this));
first.setEnabled(false);
first.setMnemonic('P');

previous=new JButton("Previous");
previous.addActionListener(new PreviousHandler(this));
previous.setEnabled(false);

next = new JButton("Next");
next.addActionListener(new NextHandler(this));
last = new JButton("Last");
last.addActionListener(new LastHandler(this));
exit= new JButton("Exit");
exit.setEnabled(false);
exit.addActionListener(new ExitHandler());


//adding buttons
bottom1.add(first);
bottom1.add(previous);
bottom1.add(next);
bottom1.add(last);
bottom2.add(exit);


if (totalq==1)
enableDisableButtons(false,false,false,false);
//adding labels for questions and anwsers
//from file
question= new JTextArea(10,50);
question.setLineWrap(true);
question.setEditable(false);

question.setText(questions[questionNos[0]]);
question.setText(questions[0]);

JScrollPane jspQ= new JScrollPane(question);


ButtonGroup bg= new ButtonGroup();
Button btn= new Button("ok");

ans1=new JRadioButton(answers[questionNos[0]][0]);
ans2 = new JRadioButton(answers[questionNos[0]][1]);
ans3= new JRadioButton(answers[questionNos[0]][2]);
ans4 = new JRadioButton(answers[questionNos[0]][3]);


ans1=new JRadioButton(answers[0][0]);
ans2=new JRadioButton(answers[0][1]);
ans3= new JRadioButton(answers[0][2]);
ans4=new JRadioButton(answers[0][3]);


center.setLayout(new GridLayout( 5,1,5,5));
centerPanel.add("North",jspQ);

center.add(ans1);
center.add(ans2);
center.add(ans3);
center.add(ans4);

centerPanel.add("Center",center);
this.getContentPane().add("North",top);
this.getContentPane().add("Center",centerPanel);
this.getContentPane().add("South",bottom);

}


class WindowEventHandler extends WindowAdapter
{
public void windowOpening(WindowEvent we)
{
System.exit(0);
}
}



class ExitHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
if (ans1.isSelected())
userChoices[i]=1;
if (ans2.isSelected())
userChoices[i]=2;
if (ans3.isSelected())
userChoices[i]=3;
if (ans4.isSelected())
userChoices[i]=4;
for(int j=0;j<userChoices.length;j++)
System.out.println(userChoices[j]);

int totalCorrect=0;

for(int j=0;j<userChoices.length;j++)
{
if (userChoices[j] == correctFinalAnswers[j])
{
totalCorrect++;
}
}
float result=(100*totalCorrect) / totalq;
JDialog resultDlg = new JDialog( app,"Result",true);
JLabel resultLbl=new JLabel("You scored " + totalCorrect +" outof" + totalq);
JButton ok = new JButton("OK");
resultDlg.getContentPane().add("Center",resultLbl);
resultDlg.getContentPane().add("South",ok);
resultDlg.pack();
Dimension d;
d= Toolkit.getDefaultToolkit().getScreenSize();
resultDlg.setLocation((d.width-resultDlg.getBounds().width)/2,(d.height-resultDlg.getBounds().height)/2);
ok.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);

resultDlg.setVisible(true);
}
}


class TimerThread extends Thread
{
int hh=0,mm=44,ss=59;

public void run()
{
while(true)
{
String tTime =new String(new Integer(hh).toString()+":"+new Integer(mm).toString()+":"+new Integer(ss).toString());

hh1.setIcon(new ImageIcon(new Integer(hh/10).toString()+".gif+"));
hh2.setIcon(new ImageIcon( new Integer(hh%10).toString() + ".gif" ));
colon1.setIcon(new ImageIcon("colon.gif"));
mm1.setIcon(new ImageIcon(new Integer(mm/10).toString()+".gif"));
mm2.setIcon(new ImageIcon(new Integer(mm%10).toString() + ".gif"));
colon2.setIcon(new ImageIcon("colon.gif"));
ss1.setIcon(new ImageIcon(new Integer(ss/10).toString()+".gif"));
ss2.setIcon(new ImageIcon(new Integer(ss%10).toString() +".gif"));
time.setText("tTime");
Font f= new Font("Serif",Font.BOLD,18);
time.setFont(f);
ss--;
if (ss==0)
{
ss=59;
mm--;
}
if (mm==0)
{
mm=59;
hh--;
}
try
{
Thread.sleep(1000);
}

catch(InterruptedException ie)
{
}
}
}
}


class NextHandler implements ActionListener{

JFrame je;
public NextHandler(JavaExam je) throws FileNotFoundException,IOException {
this.je=je;
}

public void actionPerformed(ActionEvent event )
{
if(ans1.isSelected())
userChoices[i]=1;
if(ans2.isSelected())
userChoices[i]=2;
if(ans3.isSelected())
userChoices[i]=3;
if(ans4.isSelected())
userChoices[i]=4;

i++;
if(i==totalq)
{
enableDisableButtons(true,true,false,false);
i--;
}
else
enableDisableButtons(true,true,true,true);

question.setEditable(true);
question.setText(questions[questionNos[i]]);
question.setText(questions[i]);
question.setEditable(false);

ans1.setText(answers[questionNos[i]][0]);
ans2.setText(answers[questionNos[i]][1]);
ans3.setText(answers[questionNos[i]][2]);
ans4.setText(answers[questionNos[i]][3]);

ans1.setText(answers[i][0]);
ans2.setText(answers[i][1]);
ans3.setText(answers[i][2]);
ans4.setText(answers[i][3]);

boolean flag=false;
for(int k=0;k<4;k++)
{
if(userChoices[k]==0)
flag=true;
}
if(!flag)
exit.setEnabled(true);

ans1.setSelected(false);
ans2.setSelected(false);
ans3.setSelected(false);
ans4.setSelected(false);

if(userChoices[i]==1 || userChoices[i]==0)
ans1.setSelected(true);
if(userChoices[i]==2)
ans2.setSelected(true);
if(userChoices[i]==3)
ans3.setSelected(true);
if(userChoices[i]==4)
ans4.setSelected(true);
tb.setTitle("Question "+new Integer(i+1).toString()+"/4" +" [" + ssubjectcode[i]+ "]");
je.repaint();
}
}

class LastHandler implements ActionListener
{
JFrame je;
public LastHandler(JavaExam je){
this.je=je;

}


public void actionPerformed(ActionEvent e){

if(ans1.isSelected())
userChoices[i] =1;
if(ans2.isSelected())
userChoices[i]=2;
if(ans3.isSelected())
userChoices[i]=3;
if(ans4.isSelected())
userChoices[i]=4;

enableDisableButtons(true,true,false,false);
i=totalq-1;

if(userChoices[i]==1)
ans1.setSelected(true);
if(userChoices[i]==2)
ans2.setSelected(true);
if(userChoices[i]==3)
ans3.setSelected(true);
if(userChoices[i]==4)
ans4.setSelected(true);

question.setEditable(true);
question.setText(questions[questionNos[i]]);
question.setText(questions[i]);
question.setEditable(false);

ans1.setText(answers[questionNos[i]][0]);
ans2.setText(answers[questionNos[i]][1]);
ans3.setText(answers[questionNos[i]][2]);
ans4.setText(answers[questionNos[i]][3]);

ans1.setText(answers[i][0]);
ans2.setText(answers[i][1]);
ans3.setText(answers[i][2]);
ans4.setText(answers[i][3]);

tb.setTitle("Question" + new Integer(i+1).toString() +"/4"+ "["
+ssubjectcode[i]+"]");
je.repaint();

}
}

class FirstHandler implements ActionListener
{
JFrame je;
public FirstHandler(JavaExam je)
{
this.je=je;
}
public void actionPerformed(ActionEvent ae)
{


if(ans1.isSelected())
userChoices[i]=1;
if (ans2.isSelected())
userChoices[i]=2;
if(ans3.isSelected())
userChoices[i]=3;
if (ans4.isSelected())
userChoices[i]=4;

i=0;

enableDisableButtons(false,false,true,true);
if(userChoices[i]==1)
ans1.setSelected(true);
if(userChoices[i]==2)
ans2.setSelected(true);
if(userChoices[i]==3)
ans3.setSelected(true);
if(userChoices[i]==4)
ans4.setSelected(true);

question.setEditable(true);

question.setText(questions[questionNos[i]]);
question.setText(questions[i]);
question.setEditable(false);

ans1.setText(answers[questionNos[i]][0]);
ans2.setText(answers[questionNos[i]][1]);
ans3.setText(answers[questionNos[i]][2]);
ans4.setText(answers[questionNos[i]][3]);

ans1.setText(answers[i][0]);
ans2.setText(answers[i][1]);
ans3.setText(answers[i][2]);
ans4.setText(answers[i][3]);

tb.setTitle("Question"+new Integer(i).toString()
+"/4"+"[" +ssubjectcode[i]+"]");
je.repaint();
}
}
class PreviousHandler implements ActionListener
{
JFrame je;
public PreviousHandler(JavaExam je)
{
this.je = je;
}
public void actionPerformed(ActionEvent ae){

if (ans1.isSelected())
userChoices[i]=1;
if (ans2.isSelected())
userChoices[i]=2;
if (ans3.isSelected())
userChoices[i]=3;
if (ans4.isSelected())
userChoices[i]=4;
i--;
if(userChoices[i]==1)
ans1.setSelected(true);
if(userChoices[i]==2)
ans2.setSelected(true);
if (userChoices[i]==3)
ans3.setSelected(true);
if(userChoices[i]==4)
ans4.setSelected(true);

if(i==0)
enableDisableButtons(false,false,true,true);
else
enableDisableButtons(true,true,true,true);


question.setEditable(true);

question.setText(questions[questionNos[i]]);
question.setText(questions[i]);
question.setEditable(false);

ans1.setText(answers[questionNos[i]][0]);
ans2.setText(answers[questionNos[i]][1]);
ans3.setText(answers[questionNos[i]][2]);
ans4.setText(answers[questionNos[i]][3]);

ans1.setText(answers[i][0]);
ans2.setText(answers[i][1]);
ans3.setText(answers[i][2]);
ans4.setText(answers[i][3]);

tb.setTitle("Question " +new Integer(i+1).toString()
+"/4"+ "[" + ssubjectcode[i]+"]");
je.repaint();
}
}

public void enableDisableButtons(boolean f,boolean p,boolean n,boolean l)
{
first.setEnabled(f);
previous.setEnabled(p);
next.setEnabled(n);
last.setEnabled(l);
}

}

Pl bear with me for the modification done on this code.rest are as is.for the clarification
[ December 19, 2004: Message edited by: C.R.Muthukumar Muthukumar ]
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:

Pl arrange to make this program executable as there is problem in reading theDisk file continuously.


Welcome to the JavaRanch, Muthkumar. We love to talk Java and help people solve problems, but we are all volunteers and most of us don't have time to dig through 773 lines of code to figure out what's going on with your code. Your best bet to getting help is to post as specific a question as possible ("there is problem" is not specific), give us all the information we need to help you, like what the symtpoms of the problem are(i.e. an exception, bad output, unexpected behavior and so on) and a reasonable piece of code that demonstrates the observed behavior. Many times I've solved my own problems just trying to explain them well enough for someone else to understand them. Let us know if we can help you!
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:


Welcome to the JavaRanch, Muthkumar. We love to talk Java and help people solve problems, but we are all volunteers and most of us don't have time to dig through 773 lines of code to figure out what's going on with your code. Your best bet to getting help is to post as specific a question as possible ("there is problem" is not specific), give us all the information we need to help you, like what the symtpoms of the problem are(i.e. an exception, bad output, unexpected behavior and so on) and a reasonable piece of code that demonstrates the observed behavior. Many times I've solved my own problems just trying to explain them well enough for someone else to understand them. Let us know if we can help you!

Well Thanks.The RandomAccessFile class is not able to the read function continuosly under GUI set up,as u can see in the code ,the iterator variable "i"
is not able to synchronisingly act if there are more text questions to be read from file on to the TextArea place (Win)though it reads first element of the text matter(Fistline or so)Kindly have a glipse once more and forward comments on the code
C.R.Muthukumar
Java is nice if it gives solution otherwise tantalising to !!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably just me being bad, but I don't look at more than about 10 lines of code on the ranch. I just don't have time to digest more.

Can you isolate the bit that doesn't work to a short method? Maybe make a skeletal main() method that calls it to demonstrate the problem? There's a pretty fair chance that during the process of doing that the problem will jump out at you. If not, a small chunk is a lot easier for us to look at.

I'm not trying to give you a hard time - just looking for a way to help you out. Cheers!
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
This is probably just me being bad, but I don't look at more than about 10 lines of code on the ranch. I just don't have time to digest more.

Can you isolate the bit that doesn't work to a short method? Maybe make a skeletal main() method that calls it to demonstrate the problem? There's a pretty fair chance that during the process of doing that the problem will jump out at you. If not, a small chunk is a lot easier for us to look at.

I'm not trying to give you a hard time - just looking for a way to help you out. Cheers!


public void PopulateQuestionsArray() throws FileNotFoundException,IOException


{



RandomAccessFile rafQuestions= new RandomAccessFile("lords.bin","rw");
try
{
long pos=70L;

while(rafQuestions.getFilePointer() < rafQuestions.length())

{
pos=rafQuestions.getFilePointer();

qNo=rafQuestions.readInt();
squestion=rafQuestions.readUTF();
subjectcode=rafQuestions.readUTF();
sca=rafQuestions.readUTF();
sans1=rafQuestions.readUTF();
sans2=rafQuestions.readUTF();
sans3=rafQuestions.readUTF();
sans4=rafQuestions.readUTF();


i++;
return;
}

totalq=i;

String[] questions=new String[i];
String[][] answers=new String[i][4];
int[] userChoices = new int[4];
String ssubjectcode[]=new String[i];
int[] correctAnswers =new int[i];


rafQuestions.seek(70L);
i=0;
while (rafQuestions.getFilePointer() <rafQuestions.length());
{

rafQuestions.readInt();

questions[i]=new String(rafQuestions.readUTF());

ssubjectcode[i]=rafQuestions.readUTF();
ssubjectcode[i]=ssubjectcode[i].trim();


correctAnswers[i] =Integer.parseInt(rafQuestions.readUTF());

answers[i][0]=new String(rafQuestions.readUTF());
answers[i][1]=new String (rafQuestions.readUTF());
answers[i][2]=new String(rafQuestions.readUTF());
answers[i][3]=new String(rafQuestions.readUTF());

i++;
}

totalq =i;
i=0;
questionNos =new int[4];{

for(int i=0;i<4;i++)
{
questionNos[i]=(int)(4*Math.random());
}
for(int i=0;i<4;i++)
{
System.out.println("questionNos["+i+"]"+questionNos[i]);
}
}

Hello,
As per requirement, the most critical codes that don't respond
for rendering its function viz, reading the text matter from the question.bin file under the gui set up, has been brought forward to u for perusal.Even though the codes are through on compilation, but non effective at the runtime as u will see .What precautions are to be taken under gui set up. Pl go through this code and then review full codes . It is to be actually tried out creating the neccessry txt file with some text matter.
Pl retry oncemore!
better late than never
Thanks for now
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
80 lines of code is still a lot to dig through. Perhaps you should work on one problem at a time, like reading a series of Strings out of a file. When you get that working, add features one at a time getting each to work before continuing on. Noone here has time to debug your program. However, in the spirit of compromise, I will tell you one thing. This loop:

will execute once. Do you see why?
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
80 lines of code is still a lot to dig through. Perhaps you should work on one problem at a time, like reading a series of Strings out of a file. When you get that working, add features one at a time getting each to work before continuing on. Noone here has time to debug your program. However, in the spirit of compromise, I will tell you one thing. This loop:

will execute once. Do you see why?

Hello and all the Cheers .Indeed ur methodology seems to be true for the execution of the whole lot of codes once, and this is exactly the same that i indicated from the beginning.Now I will try ur adding features one by one
but inorder to make the Radio buttons to render its function which is not happening even in the first instant execution of ur suggested ones(only the Text Area is reading the question from the file).Pl make one more try in the matter to make the Java Programmers in general delighted. Indeed I am very thankful for ur nice motivation for my task of getting the result.
Is there is any way to get the text read from file through
iterator "i" adjustment/modify
Cheers and thanks

 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:

will execute once. Do you see why?<hr></blockquote>
Hello and all the Cheers .Indeed ur methodology seems to be true for the execution of the whole lot of codes once, and this is exactly the same thing that i indicated from the beginning.Now I will try ur adding features one by one
At a try level:
Pl tell me atleast to get the thread working which is also a problem.
Pl review the codes as under:
class TimerThread extends Thread
{
int hh=0,mm=44,ss=59;

public void run()
{
while(true)
{
String tTime =new String(new Integer(hh).toString()+":"+new Integer(mm).toString()+":"+new Integer(ss).toString());

hh1.setIcon(new ImageIcon(new Integer(hh/10).toString()+".gif+"));
hh2.setIcon(new ImageIcon( new Integer(hh%10).toString() + ".gif" ));
colon1.setIcon(new ImageIcon("colon.gif"));
mm1.setIcon(new ImageIcon(new Integer(mm/10).toString()+".gif"));
mm2.setIcon(new ImageIcon(new Integer(mm%10).toString() + ".gif"));
colon2.setIcon(new ImageIcon("colon.gif"));
ss1.setIcon(new ImageIcon(new Integer(ss/10).toString()+".gif"));
ss2.setIcon(new ImageIcon(new Integer(ss%10).toString() +".gif"));
time.setText("tTime");
Font f= new Font("Serif",Font.BOLD,18);
time.setFont(f);
ss--;
if (ss==0)
{
ss=59;
mm--;
}
if (mm==0)
{
mm=59;
hh--;
}
try
{
Thread.sleep(1000);
}

catch(InterruptedException ie)
{
}
}
}
}

Tons & Tons of Thanks in advance
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:
Originally posted by C.R.Muthukumar Muthukumar:
[qb]
will execute once. Do you see why?<hr></blockquote>
Hello and all the Cheers .Indeed ur methodology seems to be true for the execution of the whole lot of codes once, and this is exactly the same thing that i indicated from the beginning.Now I will try ur adding features one by one
At a try level:
Pl tell me atleast to get the thread working which is also a problem.
Pl review the codes as under:
class TimerThread extends Thread
{
int hh=0,mm=44,ss=59;

public void run()
{
while(true)
{
String tTime =new String(new Integer(hh).toString()+":"+new Integer(mm).toString()+":"+new Integer(ss).toString());

hh1.setIcon(new ImageIcon(new Integer(hh/10).toString()+".gif+"));
hh2.setIcon(new ImageIcon( new Integer(hh%10).toString() + ".gif" ));
colon1.setIcon(new ImageIcon("colon.gif"));
mm1.setIcon(new ImageIcon(new Integer(mm/10).toString()+".gif"));
mm2.setIcon(new ImageIcon(new Integer(mm%10).toString() + ".gif"));
colon2.setIcon(new ImageIcon("colon.gif"));
ss1.setIcon(new ImageIcon(new Integer(ss/10).toString()+".gif"));
ss2.setIcon(new ImageIcon(new Integer(ss%10).toString() +".gif"));
time.setText("tTime");
Font f= new Font("Serif",Font.BOLD,18);
time.setFont(f);
ss--;
if (ss==0)
{
ss=59;
mm--;
}
if (mm==0)
{
mm=59;
hh--;
}
try
{
Thread.sleep(1000);
}

catch(InterruptedException ie)
{
}
}
}
}

Tons & Tons of Thanks in advance
[/QB]


I tried to use for loop in place of while, in the above codes but in vain
pl would u give more clues on the same as i don'see why it is executing once only even though iterator is kept incrementing, and thanks
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried to use for loop in place of while, in the above codes but in vain
pl would u give more clues on the same as i don'see why it is executing once only even though iterator is kept incrementing, and thanks


If the code inside a loop has a problem, changing the kind of loop isn't going to help. Read your code line by line and ask yourself what each line does. As a matter of fact, put comments after each line and repost the above code snippet.
And why, after I said you should work on one problem at a time, do you introduce another problem, the one with TimerThread?
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:



If the code inside a loop has a problem, changing the kind of loop isn't going to help. Read your code line by line and ask yourself what each line does. As a matter of fact, put comments after each line and repost the above code snippet.
And why, after I said you should work on one problem at a time, do you introduce another problem, the one with TimerThread?


I used the" ans1.setText(sans1);" statement just immeditely after the Radiobutton.....and notably it was able retieve the text matter from the bin file(under RandomaccessFile)though not the ones related to the first question(that is retrived at the TextArea Place, but for the last question's answer.As u will guide why is it so
( not the relent text matter appearing).Also, in antizipation of an earlier solution
i asked about the Thread problem as well.(u may consider optionally)
For ur perusal the codes that are able to retieve are given as under

ans1 =new JRadioButton(answers[questionNos[0]][0]);
ans2 = new JRadioButton(answers[questionNos[0]][1]);
ans3 = new JRadioButton(answers[questionNos[0]][2]);
ans4 = new JRadioButton(answers[questionNos[0]][3]);


ans1=new JRadioButton(answers[0][0]);
ans2=new JRadioButton(answers[0][1]);
ans3= new JRadioButton(answers[0][2]);
ans4=new JRadioButton(answers[0][3]);



bg.add(ans1);
bg.add(ans2);
bg.add(ans3);
bg.add(ans4);
ans1.setText(sans1);
ans2.setText(sans2);
ans3.setText(sans3);
ans4.setText(sans4);

While Wishing all the best wishes,i do hope i get the soltuion before 2005!!!starts




 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not trying to interfere in the educational process here but...

M:
the loop will execute once only because the last line is return;. The return key word causes the method to end immediately.

ms
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Southgate:
Not trying to interfere in the educational process here but...

M:
the loop will execute once only because the last line is return;. The return key word causes the method to end immediately.

ms

Thanks for now However,the problem here is to make the loop repeat the way it read the fist element(inside the bin file file)thus ensuring for the comlete Text matter. This is not happening here , make urr self now free for the soluttion .Does the mix up of int and strings (that are stored in the file require delimitter,or is it that Handlers that has to publish the textmatter is not effective if so pl suggest alternate
Enough for now &Cheers


 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:


Hello
Any new year solution for this
Thanks for now However,the problem here is to make the loop repeat the way it read the first element(inside the bin file )thus ensuring for the comlete Text matter. This is not happening here , make ur self now free for the solution .Does the mix up of int and strings (that are stored in the file require delimitter,or is it that Handlers that has to publish the text matter is not effective if so pl suggest alternate)And finally what if one
tries to handle RandomAccessfile class with an extra method to accomodate an integer to idicate buffersize calling an extended class of RAF class
(String filename,String mode,int bufsize).Please make an early solution if this is not allowed.Thanks ,Best wishes for 2005




 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy new year to you as well. As I told you on December 16, your best bet is to work on one feature at a time. We're still volunteers here and can't debug this problem with everything else that's going on in your program. Strip out the code that reads the file and make a class that reads the file and prints to the console. If you still have a problem, tell us what the input file is like, what the desired result is, what the acutal result is and post the problem code. It would be nice if the code is less than 20 lines but still a running program. Since all you are doing is reading in a file, that should be no problem.
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
Happy new year to you as well. As I told you on December 16, your best bet is to work on one feature at a time. We're still volunteers here and can't debug this problem with everything else that's going on in your program. Strip out the code that reads the file and make a class that reads the file and prints to the console. If you still have a problem, tell us what the input file is like, what the desired result is, what the acutal result is and post the problem code. It would be nice if the code is less than 20 lines but still a running program. Since all you are doing is reading in a file, that should be no problem.

Hello,
The disk file is a bin file contains questions(4nos) and answers
for all the 4 questions each of which has 4 answers besides one correct answer for each question .The question nos are also available in the same file
They are all written in the disk file by a RandomAccesFile class and got saved.The solution is required to read these question and answers through the codes(JavaExam.java)under the gui set up by using the radiobuttons and other JButtons,continuosly.
First question is able to be read,but for further null is indicated

Hope i made the point clear for happy solution
Cheers






 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry if the following sounds harsh, but if you are not even going to try to solve your problem, there is nothing we can do for you. On December 28, Mike Southgate posted the exact reason you get the first answer but no others. You have posted 3 times since then, asking the same question that he already answered. I suggested several times that you the code you posted for now and write on a small program which would just read the input file since it would be easier to debug. You have ignored this advice as well. We'd love to help you, but you still have to do the work.
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
I'm sorry if the following sounds harsh, but if you are not even going to try to solve your problem, there is nothing we can do for you. On December 28, Mike Southgate posted the exact reason you get the first answer but no others. You have posted 3 times since then, asking the same question that he already answered. I suggested several times that you the code you posted for now and write on a small program which would just read the input file since it would be easier to debug. You have ignored this advice as well. We'd love to help you, but you still have to do the work.

GoodMorning and hello!
Things are better understood than said or explained.I accept that the problem is posed in ampty number of times for a simple reason that splitting the codes results in eloborate way of exercising for its validity
As ready reckoner the codes are there fully.it needs a little correction which I am sure javaranch can render without further delay.
However if this is not a thing for me to get,please atleast have a glimpse at the article that i scibbled on Java.Pl forard ur comments if not for the codes that will motivate me to do harder work in the codes bye Best Wishes



Future Of Java in a Nut Shell
Do the current scientist accept that Java language can be one of the most enduring assets for their scientific and research endeavours?Java not only deals with business adaptations ,but it truly implements most of real world entities ,may be in any sphere whatsoever be of the subject. This affirmative statement is a real fact because of Java's Object Oriented Approach. Java is unique as for as new innovations are concerned.The very idea of classification possibilities of real world entities into classes that are imagined to be and the objects that are actually and finally made from these classes ,will speak of its merit.This is possible especially so while deploying an application strategy as an instance of a class for example.So we will be able to say any state and behaviour of an entity is going to conform to a particular class giving rise to objects to derive the behaviour and capabilties on either encapsulated way or inherited way through functionaries called methods.Thus the existence of a class so defined is very much commendable and authentic as well as ever permanent enabling for further use for else where applications.There is present and future scopes of entities. This is height of Javas Maxims The use of java language is going to be for any aspects irrespective of whether it is scientific or business orientaion or any other subjects orientaions The famous write up of Java Codes Viz Write once and run every where will speak of its Portabilty as well as robustness



 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:
As ready reckoner the codes are there fully.it needs a little correction which I am sure javaranch can render without further delay.
It might simply be a language misunderstanding, but this is how I read the above.
[ My personal translation ]
I've posted all of the code needed to solve my problem. It only needs a few small corrections. Fix it for me now without delaying and wasting my time any further.
Am I misinterpreting your post?

The purpose of Java Ranch is to provide a forum for people to help each other. Those of us that spend our personal time answering questions and helping people are not paid to do this. We do it for many reasons, but the goal is for us to help you help yourself and learn at the same time. We'd like to teach you to fish so you can feed yourself.

I post because people in the past have helped me (sort of repaying my karma balance), because I like to be a part of the community, because I really enjoy writing and learning about software, and because it feels good to help someone learn.

My boss gets to tell me what to do and demand I do it without delay. I certainly don't come here to get the same treatment. Again, if I am mistaken, I apologize, but the entire thread seems to support my view.

With much respect, please treat us with respect.
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Harkness:
Am I misinterpreting your post?

The purpose of Java Ranch is to provide a forum for people to help each other. Those of us that spend our personal time answering questions and helping people are not paid to do this. We do it for many reasons, but the goal is for us to help you help yourself and learn at the same time. We'd like to teach you to fish so you can feed yourself.

I post because people in the past have helped me (sort of repaying my karma balance), because I like to be a part of the community, because I really enjoy writing and learning about software, and because it feels good to help someone learn.

My boss gets to tell me what to do and demand I do it without delay. I certainly don't come here to get the same treatment. Again, if I am mistaken, I apologize, but the entire thread seems to support my view.

With much respect, please treat us with respect.

Hello

If u glimpse the whole lot of codes, u will know that RandomAccessFile class being used to trigger the text matter in the bin file.Please if somebody suggests as to how to retrieve datas that are persistively available, otherwise can any body render assistance to know if an iterator class be sandwitched along using whose method will i be able to read the
stuff ,if so which in place to put this and what are its methods,thus we as java persons can treat the operation of RAF class under collection pattern .pl note that my text matter in the bin file are objects grouped as arrays. Hope this would enhance u as well as me with a compromising solution.After all we r following a particular pattern used by another java person.Pl treat with++++++!!!Thanks(Pl note that text matter in bin file are not arraylist but only arrays(a)Questions,(b)4 ansewrs,(c)corectanswers etc



 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:

Hello

If u glimpse the whole lot of codes, u will know that RandomAccessFile class being used to trigger the text matter in the bin file.Please if somebody suggests as to how to retrieve datas that are persistively available, otherwise can any body render assistance to know if an iterator class be sandwitched along using whose method will i be able to read the
stuff ,if so which in place to put this and what are its methods,thus we as java persons can treat the operation of RAF class under collection pattern .pl note that my text matter in the bin file are objects grouped as arrays. Hope this would enhance u as well as me with a compromising solution.After all we r following a particular pattern used by another java person.Pl treat with++++++!!!Thanks(Pl note that text matter in bin file are not arraylist but only arrays(a)Questions,(b)4 ansewrs,(c)corectanswers etc





Hello

Since last 28th ,nobody responded, the codes as under were tried and got partial success since i am able to read the answers (in 4 RadioButtons) for any of the questions(out of 4 for example) .But still totally not operative continuos using Next or Previous buttons that are set in the program.The one time execution only occuring as pointed earlier, who would make the codes execute continuosly
....

public void populateQuestionsArray() throws FileNotFoundException,IOException
{
//FileInputStream fis=new FileInputStream("Harsha.bin");
RandomAccessFile rafQuestions= new RandomAccessFile("Harsha.bin","r");
try
{
// System.out.println("FileSize is :" +rafQuestions.length()+"bytes");
rafQuestions.seek(0);
long count1=Long.parseLong("0");//(starting posion)
long count2= Long.parseLong("1");//(no of bytes needed)


if(count1+count2 >rafQuestions.length())
count2=rafQuestions.length()-count1;
rafQuestions.seek(count1);

// while (rafQuestions.getFilePointer() < count2)

for(i=0;i<count2;i++)
{
try
{

//rafQuestions.readInt();

questionNos[i]=rafQuestions.readInt();
squestion=rafQuestions.readUTF();
subjectcode=rafQuestions.readUTF();

sans1=rafQuestions.readUTF();
sans2=rafQuestions.readUTF();
sans3=rafQuestions.readUTF();
sans4=rafQuestions.readUTF();
sca=rafQuestions.readUTF();

}

catch(EOFException e)
{
}
}



i++;

....

Pl note that that the Harsha.bin file used in RandomAccesFile class is a Disc file containing Text as said ealier..The solution is sought for continuos reading ,can any body render assistance
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:


Hello

Since last 28th ,nobody responded, the codes as under were tried and got partial success since i am able to read the answers (in 4 RadioButtons) for any of the questions(out of 4 for example) .But still totally not operative continuos using Next or Previous buttons that are set in the program.The one time execution only occuring as pointed earlier, who would make the codes execute continuosly
....

public void populateQuestionsArray() throws FileNotFoundException,IOException
{
//FileInputStream fis=new FileInputStream("Harsha.bin");
RandomAccessFile rafQuestions= new RandomAccessFile("Harsha.bin","r");
try
{
// System.out.println("FileSize is :" +rafQuestions.length()+"bytes");
rafQuestions.seek(0);
long count1=Long.parseLong("0");//(starting posion)
long count2= Long.parseLong("1");//(no of bytes needed)


if(count1+count2 >rafQuestions.length())
count2=rafQuestions.length()-count1;
rafQuestions.seek(count1);

// while (rafQuestions.getFilePointer() < count2)

for(i=0;i<count2;i++)
{
try
{

//rafQuestions.readInt();

questionNos[i]=rafQuestions.readInt();
squestion=rafQuestions.readUTF();
subjectcode=rafQuestions.readUTF();

sans1=rafQuestions.readUTF();
sans2=rafQuestions.readUTF();
sans3=rafQuestions.readUTF();
sans4=rafQuestions.readUTF();
sca=rafQuestions.readUTF();

}

catch(EOFException e)
{
}
}



i++;

....

Pl note that that the Harsha.bin file used in RandomAccesFile class is a Disc file containing Text as said ealier..The solution is sought for continuos reading ,can any body render assistance


Hello JavaEnthusiast/spepcialist/
My only doubt for clarification is that when RandomAccessFile class is executing once correctly why can't it execute further & if so where is the actual place for correction in the codes. Will any one help becoming happy as already wished during the new year Thanks a lot
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying one last time to assist you, Muthukumar. Quoting your entire previous post and saying "Please help me" doesn't add anything that can help us to help you.

Have you changed your code since your last post? If so, post it. Describe exactly what happens with more details rather than asking the same question. Also, reread this thread, for several people expressed their reasons for why they stopped trying to help you (mainly, you ignored their answer and asked the same question again).

If this is simply a language barrier, get a friend or coworker to translate for you. I think we've all been pretty clear so far.

In any case, good luck!
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Harkness:
I am trying one last time to assist you, Muthukumar. Quoting your entire previous post and saying "Please help me" doesn't add anything that can help us to help you.

Have you changed your code since your last post? If so, post it. Describe exactly what happens with more details rather than asking the same question. Also, reread this thread, for several people expressed their reasons for why they stopped trying to help you (mainly, you ignored their answer and asked the same question again).

If this is simply a language barrier, get a friend or coworker to translate for you. I think we've all been pretty clear so far.

In any case, good luck!

Hello JavaProfessionals
A hardwork for a nearly month has brought me to enable the codes for execution as it now (only )reads the text matter from disk file
sequuencially but not able to tell me the total correct answers out of the 4 questions that were put in the file . As u will now be able to indicate as to how to get the correct Random Numbers made inorder to see that it doesnot say ArraysIndexoutofBounds though this was put under try/catch block
The portion of the codes questionNos =new int[4];

OuterLoop:
while( i <= 3)

{
//int num;

Random rnd= new Random();
// double a =10.0,b=1000.0,r[];
// r= new double[5];
//for (num=0;num<10;num++)
// r[num]=Math.random() * (b-a) +a;

int num= (int)(Math.random()*1000);

//System.out.println("Random Number:"+num+"is"+r[num]);
System.out.println("Random Number : "+num+"is"+rnd.nextGaussian());

int questionNos[]=new int[num];
for(int j=0;j<=questionNos.length;j++)
{

if(num == questionNos[j])
{

continue OuterLoop;

}else


if(num < totalq)
{
questionNos[i]=num;
correctFinalAnswers[i]=correctAnswers[num];
i++;

}
}

}


totalq =4;
i=0;
}
catch(ArrayIndexOutOfBoundsException e)
{


e.printStackTrace();
System.out.println(e.getMessage());
}
}
Random Number : 394is-2.206335596895171
null
But for this ArraysIndexoutof Bounds for the code:correctFinalAnswers[i]=correctAnswers[num]; rest is ok pl help me to get the solution 100%
As always
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:
[QB]
Hello JavaProfessionals
A hardwork for a nearly month has brought me to enable the codes for execution as it now (only )reads the text matter from disk file
sequuencially but not able to tell me the total correct answers out of the 4 questions that were put in the file . As u will now be able to indicate as to how to get the correct Random Numbers made inorder to see that it doesnot say ArraysIndexoutofBounds though this was put under try/catch block
The portion of the codes questionNos =new int[4];
questionNos =new int[4];

Random rnd= new Random();
int a, b;
OuterLoop:
do
{
;

a=(int)(Math.random()*10 +1);
System.out.print("a = " +a);

b=(int) (Math.random() * 10 +1);


System.out.println("Trying b= " +b);


for(int j=1;j<=questionNos.length;j++)
{
System.out.println(j+ " "+b);


if(a == questionNos[j-1])
{



continue OuterLoop;

}else


if(a < totalq)
{
questionNos[i]=a;
correctFinalAnswers[i]=correctAnswers[a];
i++;
}
}
}
while(i<=3);




totalq =4;
i=0;
.....
Hello Java Specialist this is yet another portion of code for the same that was tried by me herein too, the result does not account for the correct answers that were clicked thru buttons it gives output as 4 out of 4 for whatever way we answer the questions (RadioButtons)Kindly throw some technical light and help Thanks
 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:
Originally posted by C.R.Muthukumar Muthukumar:
[QB]
Hello JavaProfessionals
A hardwork for a nearly month has brought me to enable the codes for execution as it now (only )reads the text matter from disk file
sequuencially but not able to tell me the total correct answers out of the 4 questions that were put in the file . As u will now be able to indicate as to how to get the correct Random Numbers made inorder to see that it doesnot say ArraysIndexoutofBounds though this was put under try/catch block
The portion of the codes questionNos =new int[4];
questionNos =new int[4];

Random rnd= new Random();
int a, b;
OuterLoop:
do
{
;

a=(int)(Math.random()*10 +1);
System.out.print("a = " +a);

b=(int) (Math.random() * 10 +1);


System.out.println("Trying b= " +b);


for(int j=1;j<=questionNos.length;j++)
{
System.out.println(j+ " "+b);


if(a == questionNos[j-1])
{



continue OuterLoop;

}else


if(a < totalq)
{
questionNos[i]=a;
correctFinalAnswers[i]=correctAnswers[a];
i++;
}
}
}
while(i<=3);




totalq =4;
i=0;
.....
Hello Java Specialist this is yet another portion of code for the same that was tried by me herein too, the result does not account for the correct answers that were clicked thru buttons it gives output as 4 out of 4 for whatever way we answer the questions (RadioButtons)Kindly throw some technical light and help Thanks

Hello java programmers

Pl let me get an idea as to how to find the total having given an array
(userChoices[] in the program) that contains 4 answers+ one correctAnswer prevailing in the disc, correctAnswers have to be added while answering via RadioButton,and the totalCorrect to be given as output.Will any one help me in completing this java coding successfully I am eager enough to get it
Thousands of thanks in advance


 
C.R.Muthukumar
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.R.Muthukumar Muthukumar:

Hello java programmers

Pl let me get an idea as to how to find the total having given an array
(userChoices[] in the program) that contains 4 answers+ one correctAnswer prevailing in the disc, correctAnswers have to be added while answering via RadioButton,and the totalCorrect to be given as output.Will any one help me in completing this java coding successfully I am eager enough to get it
Thousands of thanks in advance



Hello friends
Please pay attention to the exit class in the subject programme where
totalling is not coming as output. I feel that RandomAccessFile class objects is not being pulled in properly for the summation method called in exit class.can any one give the correct algorithm for totalling during runtime of the program.

class ExitHandler extends JRadioButton implements ActionListener{

public void actionPerformed(ActionEvent ae)
{
if (ans1.isSelected())
userChoices[i]=1;
if (ans2.isSelected())
userChoices[i]=2;
if (ans3.isSelected())
userChoices[i]=3;
if (ans4.isSelected())
userChoices[i]=4;
System.out.println(userChoices[j]);
int totalCorrectCount=0;

int cnt=0;
int[] userChoices=new int[4];{
for(j=0;j<userChoices.length;j++){

for(int j=0;j<userChoices.length;j++){

if (userChoices[j] == correctFinalAnswers[j]){
cnt++;
{
totalCorrectCount=3+totalCorrectCount++;

}
System.out.println("cnt:"+ cnt++);
System.out.println("totalCorrectCount :"+totalCorrectCount++);
}
}

int result=totalCorrectCount;
JDialog resultDlg = new JDialog(app,"Result", true);
JLabel resultLbl=new JLabel("You scored "+totalCorrectCount + "outof "+totalq);

JButton ok = new JButton("OK");
ok.addActionListener(this);
exit.addActionListener(this);
resultDlg.getContentPane().add("Center",resultLbl);
resultDlg.getContentPane().add("South",ok);
resultDlg.pack();

Dimension d;
d= Toolkit.getDefaultToolkit().getScreenSize();
resultDlg.setLocation((d.width-resultDlg.getBounds().width)/2,(d.height-resultDlg.getBounds().height)/2);
ok.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);



resultDlg.setVisible(true);

}
}


 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct me if I'm wrong, but your latest question has nothing to do with IO. You should ask it in the Swing Forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!