I have been tryin to get this to work for the past week if not two >:( with no joy. Worst of all its such a trivial problem.
The program asks you to choose a town name from a combo box when you choose the location you shoud be brought to a brand new Jframe with a populated Jtable. Now everything does what its meant to do except the jframe window which opens as the border of the window and the minmise,maximise and close buttons. You can view the database by expanding the jframe window from the bottom right corner(Click and drag it open). But i cannot leave it at that extremely unprofessional.
This design issue has been the bane of my existence for the last 2 weeks.
So I ask you out of the kindness of your hearts to do one favour or another for me:
Favour 1:
Tranfer my code into a jframe I have tried this numerous times myself but it has not worked. (A bit cheeky).
Favour 2:
Give me a step by step on how to achieve favour 1?
Or if someone has a working sample of something like this could they share it with me??
Any help would be greatly appreciated
Heres my code(Java Class):
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class Display_All extends JFrame
{
Object JFrame;
Object JTable;
Object JScrollpane;
public Display_All(Object town)
{
Vector columnNames = new Vector();
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
// Get column names
columnNames.addElement( "Business Name" );
columnNames.addElement( "Email" );
columnNames.addElement( "Address 1" );
columnNames.addElement( "Town" );
columnNames.addElement( "Phone" );
columnNames.addElement( "Mobile" );
columnNames.addElement( "Web Address" );
columnNames.addElement( "Owner" );
try
{
// Connect to an Access Database
String driver = "com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306/ireland";
String userid = "root";
String password = "pass";
Class.forName( driver );
Connection connection = DriverManager.getConnection( url, userid, password );
// Read data from a table
String sql = "(SELECT Activities_Name, Activities_Email,Activities_Address_1, Town, Activities_Phone ,Activities_Mobile, Activities_Web_Address, Activities_Owner FROM activities WHERE Town ='"+town+"')"
+ "UNION ALL ( SELECT Attraction_Name, Attraction_Email, Attraction_Address_1, Town, Attraction_Phone, Attraction_Mobile, Attraction_Web_Address, Attraction_Owner FROM attractions WHERE Town = '"+town+"')"
+ "UNION ALL ( SELECT BB_Name, BB_Email, BB_Address_1 ,Town, BB_Phone, BB_Mobile, BB_Web_Address, BB_Owner FROM bb WHERE Town = '"+town+"')"
+ "UNION ALL ( SELECT Hotel_Name ,Hotel_Email ,Hotel_Address_1, Town, Hotel_Phone, Hotel_Mobile, Hotel_Web_Address, Hotel_Owner FROM hotels WHERE Town = '"+town+"')"
+ "UNION ALL ( SELECT Pub_Name, Pub_Email ,Pub_Address_1, Town, Pub_Phone ,Pub_Mobile, Pub_Web_Address, Pub_Owner FROM pubs WHERE Town = '"+town+"')"
+ "UNION ALL ( SELECT Restaurant_Name, Restaurant_Email, Restaurant_Address_1, Town, Restaurant_Phone, Restaurant_Mobile, Restaurant_Web_Address, Restaurant_Owner FROM restaurant WHERE Town = '"+town+"')"
+ "UNION ALL ( SELECT Self_Catering_Name, Self_Catering_Email, Self_Catering_Address_1, Town, Self_Catering_Phone, Self_Catering_Mobile, Self_Catering_Web_Address, Self_Catering_Owner FROM self_catering WHERE Town = '"+town+"')";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
// Get row data
while (rs.next())
{
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++)
{
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
connection.close();
}
catch(Exception e)
{
System.out.println( e );
}
// Create table with database data
JTable table = new JTable(data, columnNames )
{
public Class getColumnClass(int column)
{
for (int row = 0; row < getRowCount(); row++)
{
Object o = getValueAt(row, column);
if (o != null)
{
return o.getClass();
}
}
return Object.class;
}
};
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
JPanel buttonPanel = new JPanel();
getContentPane().add( buttonPanel, BorderLayout.SOUTH );
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Display_All frame = new Display_All("town");
frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE );
frame.setVisible(true);
}
});
}
}
Heres the search box (JFrame) code:
import com.sun.rowset.JdbcRowSetImpl;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Joe Lyons
*/
public class Search_All extends javax.swing.JFrame {
/**
* Creates new form Search_All
*/
public Search_All() {
initComponents();
try {
JdbcRowSetImpl rowSet = new JdbcRowSetImpl();
rowSet.setUrl("jdbc:mysql://localhost:3306/ireland");
rowSet.setUsername("root");
rowSet.setPassword("MySQL5");
rowSet.setCommand("SELECT DISTINCT Town FROM bb order by Town");
rowSet.execute();
while (rowSet.next()) {
String SA = rowSet.getString("Town");
townComboBox.addItem(SA);
}
} catch (SQLException ex) {
Logger.getLogger(Search_All.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {
searchAllResults DA = new searchAllResults(townComboBox.getSelectedItem());
DA.setVisible(true);
dispose();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Search_All().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton exitButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel7;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JButton searchButton;
private javax.swing.JComboBox townComboBox;
// End of variables declaration
}
Thanks guys any help would be appreciated