Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more


Java Program

Posted on 2001-07-14
Medium Priority
Last Modified: 2006-11-17
I am doing a project in Java that deals with random file. I am suppose to use buttons to browse, next, previous etc. However, I am having a problem implementing the next,previous, browse, buttons. Could u help me please or refer me a site.

Question by:rwhittle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6283055
u can do that by 2 types
1 . adding a hidden field n then transfering the prevoius data
2. by using cookies
LVL 10

Expert Comment

ID: 6283157
i can write u a sample code but youll have to explain what u need from the buttons to do.

LVL 15

Expert Comment

ID: 6285331

     Please post the question elaborately. so that I can find u a solution.


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Expert Comment

ID: 6285515
code the program in such a way that everytime user sends a request it should contain values to identify the type of button user has clicked .
i suppose u r using send these values as form parameters.
then write the servlet prog as u want.

Author Comment

ID: 6286530
Mr/Mrs Nushi

I would really appreciate if you could sent me sample codes.
First of all the records are stored in a file.

a. I need the code to browse all records
b. To goto to of file
c. to move to next record etc

When the use enters a record the file stores the strings but not the integers eg.

I enter John Brown, 96q1000, history
the file is storing history, John Brown but not 96q1000

LVL 10

Expert Comment

ID: 6333255

im sorry, im wasnt here for a while ill write you some sample code today.

LVL 10

Expert Comment

ID: 6333270
i will wirte you a full application for more points.
LVL 10

Accepted Solution

Nushi earned 200 total points
ID: 6337541
//this class will show you how to use JList to move throw the records.
//you can use the buttons to navigate throw the list or to
//search specific item in the list by the search button.
//you will also need to copy and paste the following file:
//just copy it as it is and name it Nushi.txt

-- file starts here without this line

###      Save this file as:
###      Nushi.txt
###      the records are in the following format:
###      RecordIndex = RecordText
###      when we use the next/back button we just take the previuos/next
###      record. when we do search we get back the record index

Record0 = this is the text for record 0
Record1 = place here any text you want to set for record 1
Record2 = record 2 is just this text
Record3 = place here record 3 text
Record4 = are you sure you want to choose record 4?
Record5 = why did you choose me (record 5)
Record6 = whats up man? how are you doing today?

-- end file dont copy this line

//java class and again copy and paste it as it is
//and then adjust it to your needs.

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
//in the class i used properties due to
//the fact that i dont exactly what u tring to do
//im reading and writing to a property file.
 * This class implements Frame window
 * and the class functions for browsing
public class NushiBrowser {
      private JFrame            g_mainFrame = new JFrame();
      private Properties      g_prop = new Properties();
      private File            g_file = new File("Nushi.txt");
      private JList            g_list  = null;
      private JDialog            g_dialog= null;
      private JTextField      g_search= new JTextField();
      private JTextArea      g_text      = new JTextArea();
      private JScrollPane g_textScroll= new JScrollPane(g_text);
      private JPanel      g_buttonsPanel = new JPanel();
      private JPanel  g_bottomPanel  = new JPanel(new GridLayout(2,1));
      private JLabel      g_label  = new JLabel("No messages yet");
      private JButton      g_browse = new JButton("Search");
      private JButton      g_back       = new JButton(" Back ");
      private JButton      g_next       = new JButton(" Next ");
       * Default CTOR
      public NushiBrowser(){
            initFrame("Nushi's sample");
       * THis function wll draw the frame
      public void initFrame(String p_title){
            Dimension d=g_mainFrame.getToolkit().getScreenSize();
            g_mainFrame.setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
            g_mainFrame.getContentPane().setLayout(new BorderLayout());
            g_mainFrame.getContentPane().add(g_list                  , BorderLayout.WEST);
            g_mainFrame.getContentPane().add(g_textScroll      , BorderLayout.CENTER);
            g_mainFrame.getContentPane().add(g_bottomPanel      , BorderLayout.SOUTH);
            g_back.addMouseListener(new myBackLister());
            g_next.addMouseListener(new myNextLister());
            g_browse.addMouseListener(new myBrowseLister());
      //                              CODE FOR SEARCH                              //
      public void initSearchDialog(){
            JLabel            l_label  = new JLabel("Insert record to search");
            JButton            l_button = new JButton(" Search ");
            g_dialog = new JDialog( g_mainFrame , "Search record" );
            l_button.addMouseListener(new searchLister());
            Point      l_point  = g_mainFrame.getLocationOnScreen();
            Dimension l_dim = g_mainFrame.getSize();
            g_dialog.setBounds(l_point.x + l_dim.width/4   ,
                                       l_point.y + l_dim.height/4  ,
                                       l_dim.width/2, 95);
            g_dialog.getContentPane().add(l_label  , BorderLayout.NORTH);
            g_dialog.getContentPane().add(g_search , BorderLayout.CENTER);
            g_dialog.getContentPane().add(l_button , BorderLayout.SOUTH);
      //                        READ AND WRITE DATA                         //
      public void loadHistory(){
                  FileInputStream l_fin = new FileInputStream(g_file);
                  }catch(Exception e){
                  System.out.println("Exception in loadHistory: "+e);
            // Create the JList, set the number of visible rows, add a
            // listener, and put it in a JScrollPane.
            String l_entrys[]= new String[g_prop.size()];
            int i=0;
            for (Enumeration e=g_prop.keys(); e.hasMoreElements(); )
                  l_entrys[i++] = (String)(e.nextElement());
            g_list = new JList(l_entrys);
            g_list.addListSelectionListener(new NushiListListener());
            g_mainFrame.getContentPane().add( g_list , BorderLayout.WEST);
      //                        MOUSELISTENER CLASSES                        //
      class NushiListListener implements ListSelectionListener {
            /** You get three events in many cases -- one for the deselection
             *  of the originally selected entry, one indicating the selection
             *  is moving, and one for the selection of the new entry. In
             *  the first two cases, getValueIsAdjusting returns true,
             *  thus the test below when only the third case is of interest.
            public void valueChanged(ListSelectionEvent event) {
                  if (!event.getValueIsAdjusting()){
                        g_label.setText("Record Selected:    "+(String)g_list.getSelectedValue());
      class myBackLister extends MouseAdapter{
            public void mouseClicked(MouseEvent e){
                  int l_index = g_list.getSelectedIndex();
                  //we can go back only to the 0 index
                  if (l_index >0 )
      class myNextLister extends MouseAdapter{
            public void mouseClicked(MouseEvent e){
                  int l_index = g_list.getSelectedIndex();
                  //we can only go up to the last index
                  if (l_index < g_prop.size()-1 )
      class myBrowseLister extends MouseAdapter{
            public void mouseClicked(MouseEvent e){
      class searchLister extends MouseAdapter{
            public void mouseClicked(MouseEvent e){
                  int l_index=-1;
                  //look for the record in the properties list
                  String Key = (String)g_prop.get(g_search.getText());
                  if (Key != null){
                        g_list.setSelectedValue(g_search.getText() , true);
                        l_index = g_list.getSelectedIndex();
                  if (l_index != -1 )


Expert Comment

ID: 6892949
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

Expert Comment

ID: 6974341
Comment from exeprt accepted as answer

E-E Moderator

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question