Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2006, 03:21 PM
Registered User
 
Join Date: Mar 2006
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


 
Old March 14th, 2006, 04:31 AM
arp arp is offline
Authorized User
 
Join Date: Jun 2003
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







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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.