Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 4th, 2006, 03:21 PM
Registered User
 
Join Date: Mar 2006
Location: Bradford, Yorkshire, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with a program from book

Hello. I have copied this program from one of the books (Ivor Horton's Beginning JAVA 2) and there are three mistakes which I cannot correct them. If you can give me any hint it would be very helpfull to me.




import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;

public class InteractiveSQL extends JFrame
{
    public static void main(String [] args)
    {
        InteractiveSQL theApp=new InteractiveSQL("sun.jdbc.odbc.JdbcOdbcDriver","jdb c:odbc:contact","admin","rjdemo");
    }


    public InteractiveSQL(String driver, String url, String user, String password)
    {
        super("InteractiveSQL");
        setBounds(0, 0, 400, 300);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        addWindowListener(new WindowAdapter()
            {
            public void windowClosing(WindowEvent e)
            {
                dispose();
                System.exit(0);
            }
        });
        command.setToolTipText("Key SQL command and press Enter");
        getContentPane().add(command, BorderLayout.NORTH);
        status.setLineWrap(true);
        status.setWrapStyleWord(true);
        getContentPane().add(status, BorderLayout.SOUTH);
        JMenu fileMenu= new JMenu("File");
        fileMenu.setMnemonic('F');
        fileMenu.add(clearQueryItem);
        fileMenu.add(exitItem);
        menuBar.add(fileMenu);
        setJMenuBar(menuBar);
        try
        {
            Class.forName(driver);
            connection= DriverManager.getConnection(url, user, password);
            statement= connection.createStatement();
            model= new ResultsModel();
            JTable table= new JTable(model);
            table.setAutoResizeModel(JTable.AUTO_RESIZE_OFF);
            resultsPane= new JScrollPane(table);
            getContentPane().add(resultsPane, BorderLayout.CENTER);
        }
        catch(ClassNotFoundException cnfe)
        {
            System.err.println(cnfe);
        }
        catch(SQLException sqle)
        {
            System.err.println(sqle);
        }
        pack();
        setVisible(true);
    }

    JTextField command= new JTextField();
    JTextArea status= new JTextArea(3, 1);
    JScrollPane resultsPane;
    JMenuBar menuBar= new JMenuBar();
    JMenuItem clearQueryItem= new JMenuItem("Clear query");
    JMenuItem exitItem= new JMenuItem("Exit");
    Connection connection;
    Statement statement;
    ResultsModel model;
}



Thank you in Advance


Reply With Quote
  #2 (permalink)  
Old March 14th, 2006, 04:31 AM
arp arp is offline
Authorized User
 
Join Date: Jun 2003
Location: Mumbai, Maharashtra, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Following line has mistake
 table.setAutoResizeModel(JTable.AUTO_RESIZE_OFF);

Here method should be 'setAutoResizeMode' instead of 'setAutoResizeModel'
-------------------------------------

For remaining two mistakes

You have to wite class ResultsMode which exteds 'javax.swing.table.AbstractTableModel'

you can find exmaple at http://logos.cs.uic.edu/Examples%20A...ultsModel.java


Regards,
ARP


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem during execution of php program greenday Beginning PHP 2 November 12th, 2007 04:51 PM
problem with Setup Program alyeng2000 VB.NET 2002/2003 Basics 0 November 28th, 2003 04:26 AM
Address Book Program jongree VB Databases Basics 0 June 12th, 2003 09:36 AM
Address Book Program jongree Beginning VB 6 0 June 11th, 2003 05:28 PM



All times are GMT -4. The time now is 10:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.