Cannot get text file to print in jtable. Using text file as a database

Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.io.*;
public class GUIdirectory extends JFrame
implements ActionListener {
// Define the components and the layout
JLabel inputLabel_lastname = new JLabel("Last Name");
JTextField inputText_lastname = new JTextField("Last Name",15);
JLabel inputLabel_firstname = new JLabel("First Name");
JTextField inputText_firstname = new JTextField(" ",15);
JLabel inputLabel_middleinitial = new JLabel("Middle Initial");
JTextField inputText_middleinitial = new JTextField(" ",4);
JButton inputButton = new JButton("Find");
JPanel inputLayout = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
JButton jButton1 = new JButton();
//create a new table and scrollpane
JTable dataTable = new JTable();
JScrollPane dataTableScrollPane = new JScrollPane();
public static void main(String args[]) {
GUIdirectory gui = new GUIdirectory("Telephone Directory");
gui.show();
gui.pack();
//TokenTest tt = new TokenTest();
//gui.dbTest();
public GUIdirectory(String Title) {
super(Title);
// Add ourselves as a listener for the window closing
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
exitWindow(1); }
inputLabel_lastname.setLabelFor(inputText_lastname);
inputText_lastname.setHorizontalAlignment(JTextField.RIGHT);
inputText_lastname.addActionListener(this);
inputLabel_firstname.setLabelFor(inputText_firstname);
inputText_firstname.setHorizontalAlignment(JTextField.RIGHT);
inputText_firstname.addActionListener(this);
inputLabel_middleinitial.setLabelFor(inputText_middleinitial);
inputText_middleinitial.setHorizontalAlignment(JTextField.RIGHT);
inputText_middleinitial.addActionListener(this);
inputButton.addActionListener(this);
inputLayout.add(inputLabel_lastname);
inputLayout.add(inputText_lastname);
inputLayout.add(inputLabel_firstname);
inputLayout.add(inputText_firstname);
inputLayout.add(inputLabel_middleinitial);
inputLayout.add(inputText_middleinitial);
inputLayout.add(inputButton);
getContentPane().setLayout(new BorderLayout(5,5));
getContentPane().add("North",inputLayout);
dataTableScrollPane.setViewportView(dataTable);
getContentPane().add("Center",dataTableScrollPane);
// A default method, primarily used for testing.
public void actionPerformed(ActionEvent evt) {
GUIdirectory gui = new GUIdirectory();
gui.dbTest();
void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
String hold;
try {
File f = new File("customer.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
Vector dataVector = new Vector();
Vector headVector = new Vector(2);
Vector row = new Vector();
// read the record of the text database
while ( (dbRecord = dis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbRecord, ",");
while (st.hasMoreTokens()) {
row.addElement(st.nextToken());
System.out.println("Inside nested loop: " + row);
System.out.println("inside loop: " + row);
dataVector.addElement(row);
System.out.println("outside loop: " + row);
headVector.addElement("Title");
headVector.addElement("Type");
dataTable = new JTable(dataVector, headVector);
dataTableScrollPane.setViewportView(dataTable);
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error!" + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
} // end if
} // end finally
} // end dbTest
// Exits the program upon closing the window
public void exitWindow(int i) {
System.exit(i);
public GUIdirectory() {
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
jButton1.setText("jButton1");
this.getContentPane().add(jButton1, BorderLayout.CENTER);

Nothing happens because in the actionPerformed() method you are creating a new version of GUIdirectory. You just want to execute the dbTest() method of the current instance of GUIdirectory.
The code should be:
public void actionPerformed(ActionEvent evt)
//GUIdirectory gui = new GUIdirectory();
//gui.dbTest();
dbTest();

Similar Messages

  • Cant get data from text file to print into Jtable

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest

    Here's a thread that loads a text file into a JTable:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
    And my reply in this thread shows how you can use a text file as a simple database:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342380

  • When I try to click on print in Mapquest and PDF documents I cannot get the popup to print the page

    When I try to click on print in Mapquest and PDF documents I cannot get the popup to print the page when I click on "print."
    I have to type the URL in Google Chrome browser and the print button works fine.
    How can I get the print popup to work in Firefox 6.0?

    My sister's 5s is having the same issue since yesterday.
    Neither resetting via holding home+power buttons helped, nor the "reset all settings" in the settings. The only option left is erasing the iPhone and setting it up as a new phone ( or restoring from a backup?)

  • I cannot get my ipad to print using my wi if printer. It works with my computer

    I cannot get my iPad to print with my wifi printer but it prints from my computer

    Is your printer listed on this page as supporting AirPrint : http://support.apple.com/kb/HT4356 ?
    If it doesn't support AirPrint then you could see if the printer manufacturer has their own app in the store which supports it (e.g. Epson have an iPrint app, and HP have an ePrint app). If not then there are third-party printer apps such as Print n Share and PrintCentral Pro which might work with it

  • I have an iphone 4 and cannot get my mute off when I am using Facetime. I can hear them, but they can't hear me. When I touch the mute button, nothing happens. Can someone please tell me how to fix this?

    I have an iphone 4 and cannot get my mute off when I am using Facetime. I can hear them, but they can't hear me. When I touch the mute button, nothing happens. Can someone please tell me how to fix this?

    the mute button is a switch you need to flip, not touch. if you look at it and see color, its on.

  • HT1338 ical error pop up, "The server responded with an error". Cannot get it to go away and cant use my ical because of it

    ical error pop up, "The server responded with an error". Cannot get it to go away and cant use my ical because of it

    How are you syncing your contacts?
    Contacts Troubleshooting
    Contacts - Troubleshooting iCloud Contacts

  • Cannot get itunes to update to 10.5 using xp media edition?

    cannot get itunes to update to 10.5 using xp media edition?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes for Windows forums.
    Regards.

  • TS3899 I am getting the message: Cannot Get Mail the "email address" is in use on another device. What is the remedy

    I am getting the message: Cannot Get Mail the "email address" is in use on another device. How do I fix this.

    Hello groriguez,
    The following article provides further information regarding the error you're experiencing.
    iOS: 'Mailbox Locked', account is in use on another device, or prompt to re-enter POP3 password
    http://support.apple.com/kb/TS2621
    Cheers,
    Allen

  • Cannot get new ipad to message or facetime using my iphone number. Will only allow messaging and facetime with my email address

    cannot get new ipad to message or facetime using my iphone number. Will only allow messaging and facetime with my email address

    Using FaceTime  >  http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime
    iOS   http://support.apple.com/kb/TS3367
    About Messages
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755

  • Why do I get message "cannot get mail because another device is in use?

    Why do I keep getting "cannot get mail because another device is in use"?

    Are you logged onto your mail account on a different computer?

  • I cannot get my iphone to print on 8500 officejet.

    Just bought an Office Pro 8500A got it all set up but, cannot get my IPhone to find the printer.  I have turn off the bluetooth, loaded the lastest software on the IPhone, turned off and on the printer, router, phone, and reset the WEP secure code on the printer for my wireles router.  My compac laptop print wireless.  Lost.

    What router?  Do not use WEP, it is not in the least secure.  Switch your security to WPA with a 13+ character password.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Cannot get Samsung ML1740 to print wirelessly

    Hi everyone,
    Am new to the Apple. I have a Dell PC running Vista with my Samsung ML1740 printer attached via USB. I have a router and wireless network. I have a MacBook Pro and would like to be able to print wirelessly through my network. Right now I can print if I use the USB port. How can I go about doing this? If you can walk me through the process it will be appreciated.

    The following is several steps you can follow. Note that I have made the assumption that you already have your MacBook Pro connected via wireless to the same network as the Dell. If this is not the case then please reply.
    First thing you will need to do is share the printer in Vista and keep the share name to something short and preferably without spaces, such as ML1740. You should also check that the Guest account is enabled, as you will be asked to authenticate when you connect to the share from the Mac.
    With the printer shared you can then open System Preferences > Print & Fax on the Mac and click the + to add a queue. With the new window that appears you will see several icons, such as Default, Fax, IP and Windows. Select the Windows icon. This will show a window with three columns. The first column will show the workgroup names of the computers on the same network as the Mac. If you don't see any workgroup names then you don't have the Mac on the same network as the Dell. If you do see the workgroup name then select it and this will show the Dell computer name in the next column. When you select the Dell's name you will get prompted to authenticate. Select Guest and OK. This should now make the shared name appear in the third column. Select this and see what the Print Using menu does. This could be the last problem as many vendors printer drivers are written for direct connections only - not for connecting via Windows shares. So if you do select the ML1740 in the Print Using menu but find you cannot print then the problem is most likely due to the driver. See how you go with the above and if you get stuck at any point then please reply.

  • Cannot get ipad, iphones to print using wireless on Photosmart estation e510

    I have a photosmart  estation e-510 and I am trying to get my assorted ipads, iphones to print wireless using this printer.
    I have downloaded the iprint apps, and I have the wireless feature working on the printer. The Apple products will not recognize the printer. i am using a Cisco dual band router.
    I have searched on the forums,on HP website no help.
    Any assistance would be appreciated
    Bob
    This question was solved.
    View Solution.

    Let's start with a restart of the router.  Pull its power plug for a few seconds, plug back in and wait for it to start up.
    If that does not do it, restart your printer and your iOS devices.   Make sure all devices have the lastest firmware.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Cannot recover 'file' please try opening it using the file menu

    Hello,
    we have had some issues with document corruption in inDesign, a user this morning received the following error:
    Cannot recover 'filename.indd'. Please try to open it unsing the file menu.
    The file 'filename.indd' has been changed since adobe inDesign last quit (Error code: 11)
    When the user uses the file menu to open it it works fine
    I have googled this message but not found any information on it.
    Does anyone know what this means or how to resolve it? Does it give any clues as to why the users are having problems with documents getting corrupted.
    Thanks,
    Tom

    Also always worth a punt http://forums.adobe.com/thread/526990
    or
    http://forums.adobe.com/thread/526991

  • When I click on the Mozilla Firefox icon, I cannot get to my homepage so I can use the Internet.

    I have Windows XP. When I usually click on the Mozilla Firefox icon on my desktop, my Homepage comes up with weather, news headlines, etc. Now all I get is a screen with a search box for Google! I cannot get to the Internet anymore! Help!

    When I go to Tools, Options, General, Homepage, there is nothing in the box for Homepage. So I clicked on default. Didn't work. Tried Msn.com, didn't work. There's a box that says Show Homepage also, but can't seem to make it all work. What should be in the box that's blank? How did it change on its own? HELP!

Maybe you are looking for

  • Reinstalling itunes after updating to 8.1

    I uninstalled iTunes and reinstalled it and now i get this error message "The file iTunes Libary.itl cannot be read because it was created by a newer version of itunes." i dont get what it means i've reinstalled twice

  • To show document with  Extension  *.docx   and    *.xlsx  loaded on AS

    I have Up loaded a document with extension .XLSX and .DOCX on Application Server using webutil_file_transfer.client_ to_ AS_with_progress . The Problem : Unable To Viiew the document using SHOW_DOCUMENT. What changes to be made in Source code to view

  • Photo stream access?

    hi there, i had some trouble with my iPhone 4s and got it replaced (great service, by the way!).but i lost a lot of the pictures that were on that phone. now these pictures are all still visible on my apple tv photostream and my ipad that had photost

  • Just lost out on £200.00 from a client because of Youtube and HTML5 ;(

    Hi All, Youtube now caters for both flash and html 5 - because of this I have lost £200.00 today. The client wants both pcs and ipads to see their videos. Any one els feeling Apples pinch, because it's Jobs who started this war. And when is Adobe goi

  • Data load in Production Issue

    Hi All ! 1) Loaded data from datasource 2LIS_11_VAITM to PSA. Successfully. 2) While loading PSA to data target, the activation fails due to invalid characters. I have few options: 1) It has 200 datapackets. Correcting manually is not possible due tw