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.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 servlets.so 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.io.*;
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.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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 http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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