alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
** Copyright (c) 1998 by Timothy Gerard Endres
** <mailto:time@ice.com>  
** 
** This program is free software.
** 
** You may redistribute it and/or modify it under the terms of the GNU
** General Public License as published by the Free Software Foundation.
** Version 2 of the license should be included with this distribution in
** the file LICENSE, as well as License.html. If the license is not
** included	with this distribution, you may find a copy at the FSF web
** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
**
** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
** REDISTRIBUTION OF THIS SOFTWARE. 
** 
*/

package com.ice.sqlclient;

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import com.ice.util.AWTUtilities;


public class
CommandPanel extends JPanel
		implements ActionListener
	{
	private JTextArea		commandText;
	private JTextArea		resultText;
	private JTextField		databaseText;
	private JButton			commandButton;

	private JPanel			commandPanel;
	private JPanel			resultPanel;
	private JSplitPane		splitPane;


	public
	CommandPanel()
		{
		this.setDoubleBuffered( true );
		this.establishContents();
		}

	public void
	actionPerformed( ActionEvent event )
		{
		String command = event.getActionCommand();

		if ( command.equals( "CMD" ) )
			{
			String qResult;
			String sqlCmd = this.commandText.getText();
			System.err.println
				( "Command '" + sqlCmd + "'" );
			
			SQLClientHandler handler =
				SQLClientHandler.getHandler( "MySQL" );

			if ( handler == null )
				{
				this.resultText.setText
					( "Could not find handler '"
						+ "MySQL" + "'." );
				return;
				}
/*
			if ( ! handler.isOpen() )
				{
				System.err.println
					( "Opening handler 'MySQL'..." );

				String databaseName =
					this.databaseText.getText();

				try {
					handler.openConnection
						( "pc.ice.com", 3306,
							databaseName, "root", "", command );
					}
				catch ( SQLException ex )
					{
					this.resultText.setText
						( "SQLException: opening connection\n"
							+ ex.getMessage() );
					}
			System.err.println
				( "Handler is OPEN-ed." );
				}

			if ( handler.isOpen() )
				{
				try {
					qResult =
						handler.performSQLQuery
							( qText + "\n" );
					this.resultText.setText( qResult );
					}
				catch ( SQLException ex )
					{
					this.resultText.setText
						( "SQLException:\n" + ex.getMessage() );
					}
				}
			else
				{
			System.err.println
				( "Handler was NOT OPEN for the query!" );
				}
		*/
			}
		else
			{
			System.err.println
				( "UNKNOWN Command '" + command + "'" );
			}
		}

	private void
	establishContents()
		{
		JLabel	lbl;
		int		row = 0;

		this.setLayout( new BorderLayout() );

		this.commandPanel = new JPanel();
		this.commandPanel.setLayout( new GridBagLayout() );

		lbl = new JLabel( "Command:" );
		AWTUtilities.constrain(
			this.commandPanel, lbl,
			GridBagConstraints.NONE,
			GridBagConstraints.WEST,
			0, row, 2, 1, 0.0, 0.0 );

		++row;

		this.commandText = new JTextArea();
		AWTUtilities.constrain(
			this.commandPanel, this.commandText,
			GridBagConstraints.BOTH,
			GridBagConstraints.CENTER,
			0, row, 2, 1, 1.0, 1.0 );

		++row;
		
		this.commandButton =
			new JButton( "Perform Query" );
		this.commandButton.setActionCommand( "CMD" );
		this.commandButton.addActionListener( this );
		AWTUtilities.constrain(
			this.commandPanel, this.commandButton,
			GridBagConstraints.HORIZONTAL,
			GridBagConstraints.CENTER,
			0, row, 2, 1, 1.0, 0.0 );
		
		this.resultPanel = new JPanel();
		this.resultPanel.setLayout( new GridBagLayout() );

		row = 0;

		lbl = new JLabel( "Result:" );
		AWTUtilities.constrain(
			this.resultPanel, lbl,
			GridBagConstraints.NONE,
			GridBagConstraints.WEST,
			0, row, 1, 1, 0.0, 0.0 );

		++row;

		this.resultText = new JTextArea();
		AWTUtilities.constrain(
			this.resultPanel, this.resultText,
			GridBagConstraints.BOTH,
			GridBagConstraints.CENTER,
			0, row, 1, 1, 1.0, 1.0 );
		
		++row;

		
		this.splitPane =
			new JSplitPane
				( JSplitPane.VERTICAL_SPLIT,
					this.commandPanel, this.resultPanel );

		this.add( this.splitPane, BorderLayout.CENTER );
		}

	}


... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.