Tod Sterben

Greenhorn
+ Follow
since May 05, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Tod Sterben

How do I embed URLs & email addresses in JTextPane
so that they open default browser & email client when clicked
21 years ago
OK, code listed below compiles correctly but when I try to run the applet, I get this error:
load: GetMenuGui.class is not public or has no public constructor.
I'm mighty confused.
The HTML looks like this:
<APPLET CODE = "GetMenuGui.class"
WIDTH: 800 HEIGHT: 600 > </applet>
What am I missing?
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.lang.Object.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class GetMenuGui extends JApplet {
String wTitle;
String theName = "New Eritrea";
Vector cities;
Connection conn;
ResultSet rs;
Color white = new Color(255, 255, 255);
Color lBlue = new Color(196, 210, 234);
Dimension sSize = getToolkit().getScreenSize();
Font ArialBold12 = new Font("Arial Bold", 1, 12);
Font Arial12 = new Font("Arial", 1, 12);
Font ArialBold20 = new Font("Arial Bold", 1, 20);
public void init() {
doConnect connect = new doConnect();
conn = connect.doConnect();
drawMain();
}

public void start() {
}

/**
* Draw the output
*/
void drawMain() {
setBackground(white);
JPanel mainPanel = new JPanel();
mainPanel.setBackground(white);
JPanel scrollPanel = new JPanel();
scrollPanel.setBackground(white);
scrollPanel.setSize(sSize.width, 100);
scrollPanel.setLayout(new BoxLayout(scrollPanel, BoxLayout.Y_AXIS));
rs = getRestData(conn, theName);
JPanel header = new JPanel();
header.add(getHeader(rs, conn));
JPanel entrees = new JPanel();
entrees.setLayout(new BoxLayout(entrees, BoxLayout.Y_AXIS));
rs = getMenuEntrees(conn, theName, "eapetizers");
entrees.add(getMenuLines(rs, "Appetizers"));
rs = getMenuEntrees(conn, theName, "eEntrees");
entrees.add(getMenuLines(rs, "Entrees"));
rs = getMenuEntrees(conn, theName, "evegetarian");
entrees.add(getMenuLines(rs, "Vegetarian"));
entrees.setBackground(white);
scrollPanel.add(entrees);
JScrollPane sPane = new JScrollPane(scrollPanel);
sPane.setBackground(lBlue);
sPane.setPreferredSize(new Dimension(sSize.width, (sSize.height - 185)));
mainPanel.setPreferredSize(new Dimension(sSize.width, (sSize.height - 30)));
mainPanel.add(header);
mainPanel.add(sPane);
getContentPane().add(mainPanel);
//pack();
}

/**
* Gets the menuEntees attribute of the GetMenuGui object
*
*@param conn Description of the Parameter
*@param theName Description of the Parameter
*@param tbName Description of the Parameter
*@return The menuEntees value
*/
ResultSet getMenuEntrees(Connection conn, String theName, String tbName) {
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT e.* FROM eRestaurants.";
SQLStatement = SQLStatement + tbName.trim() + " e,";
SQLStatement = SQLStatement +
"eRestaurants.eRestaurant r where ";
SQLStatement = SQLStatement +
"r.rest_id = e.rest_id and r.name = '" +
theName + "';";
System.out.println(SQLStatement);
ResultSet rs = stmt.executeQuery(SQLStatement);
return rs;
} catch (SQLException e) {
System.err.println(e.getMessage());
return null;
}
}

/**
* Gets the menuBooze attribute of the GetMenuGui object
*
*@param conn Description of the Parameter
*@param theName Description of the Parameter
*@return The menuBooze value
*/
ResultSet getMenuBooze(Connection conn, String theName) {
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT e.* FROM eRestaurants.ebooze e,";
SQLStatement = SQLStatement +
"eRestaurants.eRestaurant r where ";
SQLStatement = SQLStatement +
"r.rest_id = e.rest_id and r.name = '" +
theName + "';";
System.out.println(SQLStatement);
ResultSet rs = stmt.executeQuery(SQLStatement);
return rs;
} catch (SQLException e) {
System.err.println(e.getMessage());
return null;
}
}

/**
* Gets the restData attribute of the GetMenuGui object
*
*@param conn Description of the Parameter
*@param theName Description of the Parameter
*@return The restData value
*/
ResultSet getRestData(Connection conn, String theName) {
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT name, ";
SQLStatement = SQLStatement + " street1, ";
SQLStatement = SQLStatement + " street2,";
SQLStatement = SQLStatement + " city,";
SQLStatement = SQLStatement + " zip,";
SQLStatement = SQLStatement + " phone,";
SQLStatement = SQLStatement + " fax,";
SQLStatement = SQLStatement + " email,";
SQLStatement = SQLStatement + " wsite,";
SQLStatement = SQLStatement + " header,";
SQLStatement = SQLStatement + " blurb,";
SQLStatement = SQLStatement + " rest_id";
SQLStatement = SQLStatement + " FROM eRestaurants.eRestaurant";
SQLStatement = SQLStatement + " where name = '" + theName +
"';";
ResultSet rs = stmt.executeQuery(SQLStatement);
return rs;
} catch (SQLException e) {
System.err.println(e.getMessage());
return null;
}
}

/**
* Gets the menuParts attribute of the GetMenuGui object
*
*@param RS Description of the Parameter
*@param theType Description of the Parameter
*@return The menuParts value
*/
JPanel getMenuLines(ResultSet RS, String theType) {
JPanel theMenuPanel = new JPanel();
theMenuPanel.setLayout(new BoxLayout(theMenuPanel, BoxLayout.Y_AXIS));
JPanel theDishPanel = new JPanel();
JTextPane jtp = new JTextPane();
int row = 0;
boolean isFirst = true;
try {
while (RS.next()) {
if (isFirst) {
JPanel typePanel = new JPanel();
typePanel.setPreferredSize(new Dimension(sSize.width,
30));
JLabel theTypeLabel = new JLabel(theType);
theTypeLabel.setFont(ArialBold20);
typePanel.add(theTypeLabel);
typePanel.setBackground(white);
theMenuPanel.add(typePanel);
isFirst = false;
}
theDishPanel = new JPanel();
theDishPanel.setLayout(new BoxLayout(theDishPanel,
BoxLayout.X_AXIS));
jtp = new JTextPane();
jtp.setPreferredSize(new Dimension((int) (sSize.width * .2),
50));
String tText = ++row + " ) " + rs.getString("eName");
jtp.setText(tText.trim());
jtp.setFont(ArialBold12);
jtp.setEditable(false);
theDishPanel.add(jtp);
jtp = new JTextPane();
jtp.setPreferredSize(new Dimension((int) (sSize.width * .65), 50));
tText = rs.getString("eDescr");
jtp.setText(tText);
jtp.setFont(Arial12);
jtp.setEditable(false);
theDishPanel.add(jtp);
jtp = new JTextPane();
jtp.setPreferredSize(new Dimension((int) (sSize.width * .1), 50));
tText = rs.getString("ePrice");
jtp.setText(tText);
jtp.setFont(Arial12);
jtp.setEditable(false);
theDishPanel.add(jtp);
theDishPanel.setBackground(white);
theMenuPanel.add(theDishPanel);
}
theMenuPanel.setBackground(white);
return theMenuPanel;
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
return null;
}

/**
* Gets the header attribute of the GetMenuGui object
*
*@param RS Description of the Parameter
*@param conn Description of the Parameter
*@return The header value
*/
JPanel getHeader(ResultSet RS, Connection conn) {
JPanel theHeader = new JPanel();
theHeader.setLayout(new BoxLayout(theHeader, BoxLayout.X_AXIS));
theHeader.setPreferredSize(new Dimension(sSize.width, 125));
JTextPane header = new JTextPane();
header.setPreferredSize(new Dimension((int) (sSize.width * .75), 125));
String findUs = "";
String blurb = "";
String Street1 = "Address: ";
String Street2 = "";
String city = "";
String zip = "";
String phone = "Phone: ";
String fax = "Fax: ";
String email = "E-Mail: ";
String wSite = "Web Site: ";
ResultSet theImages;
int idRest = 0;
try {
while (RS.next()) {
if (RS.getString("street1") != null) {
findUs = Street1 + RS.getString("street1") + " ";
}
if (RS.getString("street2") != null) {
findUs = findUs + Street2 + RS.getString("street2") +
" ";
}
if (RS.getString("city") != null) {
findUs = findUs + city + RS.getString("city");
}
if (RS.getString("zip") != null) {
findUs = findUs + zip + ", " + RS.getString("zip");
}
if (RS.getString("phone") != null) {
findUs = findUs + "\n" + phone +
formatPhone(RS.getString("phone"));
}
if (RS.getString("fax") != null) {
findUs = findUs + " \n" + fax +
formatPhone(RS.getString("fax"));
}
if (RS.getString("email") != null) {
findUs = findUs + "\n" + email + RS.getString("email");
}
if (RS.getString("wSite") != null) {
findUs = findUs + "\n" + wSite + RS.getString("wSite");
}
if (RS.getString("blurb") != null) {
blurb = (RS.getString("blurb"));
}
try {
theImages = getImages(RS.getInt("rest_id"), conn);
while (theImages.next()) {
String theImage = theImages.getString("Img1Filename");
theImage = theImage.trim();
ImageIcon ii = new ImageIcon(new URL(theImage));
theHeader.add(new JLabel(resizeImage(ii)));
}
} catch (SQLException eSql2) {
System.err.println("SQL Error " + eSql2.getMessage());
} catch (MalformedURLException mal) {
System.err.println(
"Maformed URL Error " + mal.getMessage());
}
header.setFont(ArialBold12);
header.setText(findUs + "\n\n" + blurb);
header.setEditable(false);
JScrollPane theScroll = new JScrollPane(header);
theHeader.add(theScroll);
}
theHeader.setBackground(white);
return theHeader;
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
return null;
}

/**
* Gets the images attribute of the GetMenuGui object
*
*@param idRest Description of the Parameter
*@param conn Description of the Parameter
*@return The images value
*/
ResultSet getImages(int idRest, Connection conn) {
String SQLStatement = "";
ResultSet theImages;
try {
Statement stmt = conn.createStatement();
SQLStatement = "select Img1Filename,";
SQLStatement = SQLStatement + "Img2Filename ";
SQLStatement = SQLStatement + "from eRestaurants.eImages ";
SQLStatement = SQLStatement + "where idRest = " + idRest + ";";
theImages = stmt.executeQuery(SQLStatement);
return theImages;
} catch (SQLException e) {
System.err.println(e.getMessage());
return null;
}
}

/**
* Description of the Method
*
*@param phone Description of the Parameter
*@return Description of the Return Value
*/
String formatPhone(String phone) {
phone = phone.trim();
if (phone.length() > 0) {
return " (" + phone.substring(0, 3) + ") " +
phone.substring(3, 6) + "-" + phone.substring(6, 10);
}
return phone;
}

/**
* Description of the Method
*
*@param iIcon Description of the Parameter
*@return Description of the Return Value
*/
ImageIcon resizeImage(ImageIcon iIcon) {
Image iImage;
double iconWide = ((double) iIcon.getIconWidth() / (double) iIcon.getIconHeight());
iImage = iIcon.getImage();
iImage = iImage.getScaledInstance((int) (125 * iconWide), 125, 1);
iIcon = new ImageIcon(iImage);
return iIcon;
}
}
[ May 15, 2003: Message edited by: Tod Sterben ]
21 years ago
I have a Swing app that I need to convert into a servlet (I think & I hope). I don't want to have to convert all of this to HTML.
It has Scroll panes, JPanel, JComboBoxes & JLists.
Also SQL.
Is it possible to have this work?
21 years ago
Can I make the cells wrap? Some of the fields will contain up to 255 characters.
21 years ago
I want to open a new frame when a selection is made from a JList and send the value in the selected cell in the JList to the new frame.
How do I set up a listener to do that without the code (listed below) producing two rows and also two new windows, as shown below

0 [Cliff House Restaurant, 1090 Point Lobos Avenue, San Francisco - Outer Sunset, , California Cuisine]
0 [Cliff House Restaurant, 1090 Point Lobos Avenue, San Francisco - Outer Sunset, , California Cuisine]

public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
if (theList.isSelectionEmpty()) {
return;
} else {
if (isDone == false) {
int index = theList.getSelectedIndex();
System.out.println(index + " " + theList.getSelectedValue());
Object theValue = theList.getSelectedValue();
String pString = theValue.toString();
Out2SecondGui newgoo = new Out2SecondGui((String) "two");
newgoo.drawMain();
isDone = true;
}
}
}
[ May 07, 2003: Message edited by: Tod Sterben ]
21 years ago
I want to use JList to scroll data I will be loading to it from a database. I would like to have different cells in the list for the different fields I am bringing back so that I could put different listeners attached to each cell.
How can this be done?
21 years ago
ADVERTISEMENT


I'm trying to do a Swing thing where people can look up businesses
by any of the following:
Zone (collection of cities in a metro area)
City
General type of business (ie Auto related)
Specific type (Mufflers)
by selecting one or more of the above from combo boxes
The data that fills the combo boxes is stored in a mySQL database
along with individual businesses (addresses,phones, URLs,etc)
When the users select from one or more of the boxes, they click on a
button with a listener that generates the SQL (correctly, I am
getting the results I expect when I extract the statement) and puts
it into a JTable via a DefaultTableModel. When I call getValueAt()
on the table, I get the value which shows the table is loading, but I
never get the table to show in the scroll pane, as I need to do.
I have tried an internal class and a separate class with no success.
How do I get the table to show in the main frame after it gets loaded
by the listener?
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.lang.Object.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.net.*;
/**
* Description of the Class
*
*@a... JOHN
*@c... April 27, 2003
*/
class businessMainGui
extends JFrame {
/**
* Constructor for the businessMainGui object
*/
String wTitle;
Vector cities;
Connection conn;
int aIndex = -1;
ActionListener cListen;

/**
* Constructor for the businessMainGui object
*
*@p... Title Description of the Parameter
*/
businessMainGui(String Title) {
wTitle = Title;
}

/**
* Description of the Method
*/
void drawMain() {
try {
int wHeight = 0;
setDefaultCloseOperation
(WindowConstants.EXIT_ON_CLOSE);
setTitle(wTitle);
conn = doConnect();
Dimension sSize = getToolkit().getScreenSize
();
wHeight = (int) (sSize.height * .95);
Dimension logoSize = new Dimension
(sSize.width, (sSize.height / 10));
Dimension listSize = new Dimension
(sSize.width, 20);
Dimension labelSize = new Dimension
(sSize.width, (sSize.height / 20));
Dimension labelWidth = new Dimension
((sSize.width / 5),
labelSize.height);
Dimension go = new Dimension(sSize.width, 30);
System.out.println(labelSize.width + " w LS
h " + labelSize.height);
Dimension scrollSize = new Dimension
(sSize.width,
(7 * (sSize.height / 10)));
System.out.println(scrollSize.height + " " +
logoSize.height);
JPanel mainPanel = new JPanel(new GridLayout
(2, 1));
mainPanel.setPreferredSize(new Dimension
(sSize.width, (int) (sSize.height * .9)));
mainPanel.setBackground(new Color(255, 0,
255));
mainPanel.setLayout(new BoxLayout(mainPanel,
BoxLayout.Y_AXIS));
//JPanel logoPanel = new JPanel();
ImageIcon ii = new ImageIcon(new URL
("http://suhoff.ru/albums/general/09150010_G.thumb.jpg"));
//logoPanel.add(new JLabel(ii));
//logoPanel.setPreferredSize(new Dimension
(sSize.width, 113));
//logoPanel.setLayout(new BoxLayout
(logoPanel, BoxLayout.Y_AXIS));
//logoPanel.setBackground(new Color(255, 255,
255));
JPanel selectPanel = new JPanel();
selectPanel.setLayout(new BoxLayout
(selectPanel, BoxLayout.Y_AXIS));
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new GridLayout(1, 5));
JLabel zone = new JLabel("Select by Zone");
zone.setPreferredSize(labelWidth);
labelPanel.add(zone);
JLabel city = new JLabel("Select by City");
city.setPreferredSize(labelWidth);
labelPanel.add(city);
JLabel business = new JLabel("Select by
business");
business.setPreferredSize(labelWidth);
labelPanel.add(business);
JPanel listPanel = new JPanel();
listPanel.setLayout(new BoxLayout(listPanel,
BoxLayout.X_AXIS));
JPanel top3 = new JPanel();
labelPanel.setPreferredSize(listSize);
labelPanel.setBackground(new Color(169, 209,
211));
listPanel.setPreferredSize(listSize);
listPanel.setBackground(new Color(0, 0, 200));
JComboBox cbArea = new JComboBox(getAreas
(conn));
cbArea.setPreferredSize(labelWidth);
aIndex = cbArea.getSelectedIndex();
System.out.println("index = " +
cbArea.getSelectedIndex());
JComboBox cbCities = new JComboBox(getCities
(conn));
cbCities.setPreferredSize(labelWidth);
JComboBox cbbusiness = new JComboBox
(getbusiness(conn));
cbbusiness.setPreferredSize(labelWidth);
JComboBox cbBusgrp = new JComboBox
(getbusinessGroup(conn));
cbBusgrp.setPreferredSize(labelWidth);
listPanel.add(cbArea);
listPanel.add(cbCities);
listPanel.add(cbBusgrp);
listPanel.add(cbbusiness);
selectPanel.add(labelPanel,
BorderLayout.NORTH);
selectPanel.add(listPanel,
BorderLayout.SOUTH);

JPanel goPanel = new JPanel();
goPanel.setBackground(new Color(25, 252, 25));
goPanel.setPreferredSize(go);
JButton bGo = new JButton("Get Your
Business");
bGo.setPreferredSize(new Dimension(160, 20));
goPanel.add(bGo);
Dimension dTop3 = new Dimension
(logoSize.width, 10);
top3.setBackground(new Color(130, 25, 25));
top3.setLayout(new BoxLayout(top3,
BoxLayout.Y_AXIS));
//top3.add(logoPanel);
top3.add(selectPanel);
top3.add(goPanel);
top3.setPreferredSize(dTop3);
mainPanel.add(top3);
JPanel ps;
ps = new JPanel();
ps.setBackground(new Color(255, 255, 255));
ps.setLayout(new BoxLayout(ps,
BoxLayout.Y_AXIS));
JScrollPane scrollThis = new JScrollPane(ps);
scrollThis.setPreferredSize(scrollSize);
scrollThis.setBackground(new Color(0, 255,
0));
bGo.addActionListener(new cbListener(
cbArea,
cbCities,
cbBusgrp,
cbbusiness,
scrollThis,
ps,
conn,
mainPanel
)
);
mainPanel.add(scrollThis);
getContentPane().add(mainPanel);
pack();
setVisible(true);
} catch (MalformedURLException mal) {
System.out.println
("http://www.cliffhouse.com/images/logonew1.gif");
}
}

/**
* Description of the Method
*
*@r... Description of the Return Value
*/
Connection doConnect() {
Connection connection = null;
try {
Class.forName
("com.mysql.jdbc.Driver").newInstance();
System.out.println("no error");
//Connect to MySQL giving user id and password
String connectionURL
= "jdbc:mysql://localhost:3306/";
connection = DriverManager.getConnection
(connectionURL, "root", "");
return connection;
} catch (ClassNotFoundException e) {
// print trace of error
System.err.println(
"Couldn't find the the
MySQL " + "database driver: " +
e.getMessage());
return connection;
} catch (Exception e) {
e.printStackTrace();
return connection;
}
}

/**
* Gets the cities attribute of the businessMainGui object
*
*@p... conn Description of the Parameter
*@r... The cities value
*/
Vector getCities(Connection conn) {
Vector eCities = new Vector(1);
eCities.add(" ");
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT * FROM
eBusiness.ecities order by 2";
ResultSet rs = stmt.executeQuery
(SQLStatement);
// move to first row of result set
while (rs.next()) {
String loadThis = rs.getString
("City");
loadThis = loadThis.trim();
eCities.add(loadThis);
}
// tidy up and disconnect
rs.close();
stmt.close();
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
System.out.println("Vector eCities has " +
eCities.size() +
" cities");
return eCities;
}

/**
* Gets the business attribute of the businessMainGui object
*
*@p... conn Description of the Parameter
*@r... The business value
*/
Vector getbusiness(Connection conn) {
Vector ebusiness = new Vector(1);
ebusiness.add(" ");
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT bus_name FROM
eBusiness.ebusiness order by bus_name";
ResultSet rs = stmt.executeQuery
(SQLStatement);
// move to first row of result set
while (rs.next()) {
String loadThis = rs.getString
("bus_name");
loadThis = loadThis.trim();
ebusiness.add(loadThis);
}
// tidy up and disconnect
rs.close();
stmt.close();
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
System.out.println(
"Vector business has " +
ebusiness.size() + " business types");
return ebusiness;
}
/**
* Gets the areas attribute of the businessMainGui object
*
*@p... conn Description of the Parameter
*@r... The areas value
*/
Vector getAreas(Connection conn) {
Vector eAreas = new Vector(1);
eAreas.add(" ");
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT descr FROM
eBusiness.areas order by descr";
ResultSet rs = stmt.executeQuery
(SQLStatement);
// move to first row of result set
while (rs.next()) {
String loadThis = rs.getString
("descr");
loadThis = loadThis.trim();
eAreas.add(loadThis);
}
// tidy up and disconnect
rs.close();
stmt.close();
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
System.out.println("Vector areas has " + eAreas.size
() + " areas");
return eAreas;
}

/**
* Gets the businessGroup attribute of the businessMainGui
object
*
*@p... conn Description of the Parameter
*@r... The businessGroup value
*/
Vector getbusinessGroup(Connection conn) {
Vector ebusiness = new Vector(1);
ebusiness.add(" ");
try {
Statement stmt = conn.createStatement();
String SQLStatement = "SELECT descr FROM
eBusiness.Busgrp order by descr";
ResultSet rs = stmt.executeQuery
(SQLStatement);
// move to first row of result set
while (rs.next()) {
String loadThis = rs.getString
("descr");
loadThis = loadThis.trim();
ebusiness.add(loadThis);
}
// tidy up and disconnect
rs.close();
stmt.close();
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
System.out.println(
"Vector business has " +
ebusiness.size() + " business groups");
return ebusiness;
}
}
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.sql.*;
import javax.swing.table.*;
import java.lang.Object.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
/**
* Description of the Class
*
*@a... JOHN
*@c... May 1, 2003
*/
class cbListener
implements ActionListener {
/**
* Description of the Field
*/
public int aIndex;
/**
* Description of the Field
*/
public int cbIndex;
JComboBox cbArea;
JComboBox cbCity;
JComboBox cbType;
JComboBox cbBusiness;
JPanel inPanel;
JScrollPane iPane;
JPanel iPs;
JPanel mainPanel;
Connection conn;

/**
* Constructor for the cbListener object
*
*@p... pScroll Description of the Parameter
*@p... cbArea Description of the Parameter
*@p... cbCity Description of the Parameter
*@p... cbType Description of the Parameter
*@p... cbBusiness Description of the Parameter
*@p... pPs Description of the Parameter
*@p... conn Description of the Parameter
*@p... mainPanel Description of the Parameter
*/
cbListener(JComboBox cbArea, JComboBox cbCity, JComboBox
cbType,
JComboBox cbBusiness, JScrollPane pScroll,
JPanel pPs,
Connection conn, JPanel mainPanel) {
this.cbArea = cbArea;
this.cbCity = cbCity;
this.cbType = cbType;
this.cbBusiness = cbBusiness;
this.conn = conn;
iPane = pScroll;
iPs = pPs;
this.mainPanel = mainPanel;
System.out.println("here is the constructor");
}

/**
* Description of the Method
*
*@p... e Description of the Parameter
*/
public void actionPerformed(ActionEvent e) {
aIndex = isSelected();
System.out.println("Action " + aIndex);
DefaultTableModel theBusiness = getBusinessaurants
(getSQLString());
JTable table = new JTable(theBusiness);
iPs.add(table);
System.out.println("Table row count " +
table.getRowCount());
iPane.add(iPs);
mainPanel.add(iPane);
mainPanel.repaint();
}

/**
* Description of the Method
*
*@r... The sQLString value
*/
public String getSQLString() {
String sqlSelect = "Select
eBusiness.name,eCities.city,eBusiness.bus_name ";
String sqlFrom = " from eBusiness.eBusiness,
eBusiness.eBusiness,eBusiness.eCities ";
String sqlWhere = " where eBusiness.idCity =
eCities.id and ";
String finalString = "";
sqlWhere = sqlWhere + " eBusiness.cuis_type =
eBusiness.id ";
String addString = ((String) cbArea.getSelectedItem()
+ (String) cbCity.getSelectedItem()
+ (String) cbType.getSelectedItem()
+ (String) cbBusiness.getSelectedItem
());
addString.trim();
if (addString.length() > 0) {
finalString = sqlAdded(sqlFrom, sqlWhere);
}
return (sqlSelect + finalString);
}

/**
* Description of the Method
*
*@p... sqlFrom Description of the Parameter
*@p... sqlWhere Description of the Parameter
*@r... Description of the Return Value
*/
public String sqlAdded(String sqlFrom, String sqlWhere) {
String addString = ((String) cbArea.getSelectedItem
());
addString = addString.trim();
if (addString.length() > 0) {
sqlFrom = sqlFrom + ", eBusiness.areas ";
sqlWhere = sqlWhere + " and areas.descr = '"
+ addString +
"' and areas.idArea =
eCities.idArea ";
}
addString = ((String) cbCity.getSelectedItem());
addString = addString.trim();
if (addString.length() > 0) {
sqlWhere = sqlWhere + " and eCities.city = '"
+ addString +
"' and eCities.id =
eBusiness.idCity ";
}
addString = ((String) cbType.getSelectedItem());
addString = addString.trim();
if (addString.length() > 0) {
sqlFrom = sqlFrom + ", eBusiness.cuisgrp g ";
sqlWhere = sqlWhere + " and g.descr = '" +
addString +
"' and g.idCuisGrp =
eBusiness.idCuisGrp ";
}
addString = ((String) cbBusiness.getSelectedItem());
addString = addString.trim();
if (addString.length() > 0) {
sqlWhere = sqlWhere + " and
eBusiness.bus_name = '" + addString +
"' and eBusiness.id =
eBusiness.cuis_type ";
}
System.out.println(sqlFrom + " " + sqlWhere);
return sqlFrom + " " + sqlWhere;
}

/**
* Gets the selected attribute of the cbListener object
*
*@r... The selected value
*/
public int isSelected() {
System.out.println("index" + cbIndex);
iPs = new JPanel();
iPs.setLayout(new BoxLayout(iPs, BoxLayout.Y_AXIS));
for (int x = 0; x < 100; x++) {
iPs.add(new JLabel("Here are the businesses"
+ x));
}
iPs.add(new JLabel((String) cbArea.getSelectedItem
()));
System.out.println(
cbArea.getSelectedItem() + " " +
iPane.getComponentCount());
iPane.add((JPanel) iPs);
return 0;
}
/**
* Gets the businesses attribute of the cbListener object
*
*@p... sqlStatement Description of the Parameter
*@r... The businesses value
*/
DefaultTableModel getBusinesses(String sqlStatement) {
ResultSet theBusinesses;
DefaultTableModel theBusTable;
Vector newRow;
try {
Statement stmt = conn.createStatement();
theBusinesses = stmt.executeQuery
(sqlStatement);
theBusTable = new DefaultTableModel
(theBusinesses.getFetchSize(), 3);
while (theBusinesses.next()) {
newRow = new Vector();
newRow.add(theBusinesses.getString
(1));
newRow.add(theBusinesses.getString
(2));
newRow.add(theBusinesses.getString
(3));
theBusTable.addRow(newRow);
}
System.out.println("B" +
theBusinesses.getFetchSize());
System.out.println("Table theBusinessTable
has " + theBusinessTable.getRowCount() + " Businesses");
stmt.close();
return theBusinessTable;
} catch (SQLException eSql) {
System.err.println(eSql.getMessage());
}
return null;
}
}

21 years ago