hi guys i am trying to create a button that sends all the data returned from my ms access database into the fields of my jframe to the printer for a hardcopy, i have created a button to exit the frame, but now i am having difficulties creating a print button, any help or advice will be appreciated..
the coding is below it work with no problems
import java.awt.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.math.*;
import javax.swing.border.*;
import java.awt.event.*;
public class DataOut extends JFrame implements ActionListener{
private JButton btnexit;
public DataOut()
{
Vector columnNames = new Vector();
Vector data = new Vector();
try
{
// Connect to the Database
//connection object created using DriverManager class
//carpark is the name of the database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect =DriverManager.getConnection("jdbc:odbc:carpark");
// Read data from a table
String sql = "Select * from member";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
// Get column names
for (int i = 1; i <= columns; i++)
{
columnNames.addElement( md.getColumnName(i) );
}
// 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();
}
catch(Exception e)
{
System.out.println( e );
}
// Create table with database data
JTable table = new JTable(data, columnNames);
btnexit = new JButton("Exit");
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
JPanel buttonPanel = new JPanel();
getContentPane().add( buttonPanel, BorderLayout.SOUTH );
buttonPanel.add(btnexit);
btnexit.addActionListener(this);
this.setSize(450,260);
this.setLocation(500,200);
this.show();
}
public static void main(String[] args)
{
DataOut frame = new DataOut();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btnexit)
{
this.hide();
}
}
}
------------------------------------------------------------------------------------------------------
sorry if the code layout is'nt good am still a beginner....tc