problem using JCheckBox with JTextArea

hello.

i have a problem trying to get JCheckBox to work with JTextArea. what i expected to happen when i would click on a check box is that data from a table in a MS Access database would be displayed in the text area.

when i try to compile the main program (1 of 2 programs) below, i get the following 8 errors. what am i gonna do?

-jGRASP exec: javac -g E:\CP4B Project\ViewProductDetails.java

DBController.java:63: not a statement

rsmd1.getColumnName(i) + "";

^

DBController.java:69: not a statement

rs1.getObject(i) + "";

^

DBController.java:85: not a statement

rsmd2.getColumnName(i) + "";

^

DBController.java:91: not a statement

rs2.getObject(i) + "";

^

DBController.java:107: not a statement

rsmd3.getColumnName(i) + "";

^

DBController.java:113: not a statement

rs3.getObject(i) + "";

^

DBController.java:129: not a statement

rsmd4.getColumnName(i) + "";

^

DBController.java:135: not a statement

rs4.getObject(i) + "";

^

8 errors

-jGRASP wedge2: exit code for process is 1.

-jGRASP: operation complete.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.sql.*;

publicclass ViewProductDetailsextends JFrame{

JPanel pnlBox, pnlBody, pnlFooter;

JCheckBox name;

JCheckBox ageCategory;

JCheckBox type;

JCheckBox year;

JButton returnToProductMenu =new JButton("Return To Product Menu");

JTextArea jta;

Container contentpane;

DBController dbc =new DBController();

public ViewProductDetails(){

super("View Product Details");

contentpane = getContentPane();

contentpane.setLayout(new BorderLayout());

pnlBox =new JPanel();

pnlBody =new JPanel();

pnlFooter =new JPanel();

jta =new JTextArea();

jta.setFont(new Font("Serif", Font.PLAIN, 12));

jta.setLineWrap(true);

jta.setWrapStyleWord(true);

jta.setEditable(false);

name =new JCheckBox("Name");

ageCategory =new JCheckBox("Age Category");

type =new JCheckBox("Type");

year =new JCheckBox("Year");

pnlBox.add(name);

pnlBox.add(ageCategory);

pnlBox.add(type);

pnlBox.add(year);

JScrollPane jsp =new JScrollPane(jta);

pnlBody.add(jsp, BorderLayout.CENTER);

pnlFooter.add(returnToProductMenu);

contentpane.add(pnlBox,BorderLayout.NORTH);

contentpane.add(pnlBody,BorderLayout.CENTER);

contentpane.add(pnlFooter,BorderLayout.SOUTH);

pack();

setLocationRelativeTo(null);

setVisible(true);

returnToProductMenu.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

setVisible(false);

}

});

}

publicvoid viewByName(){

name.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

dbc.makeConnection();

dbc.setHostURL();

dbc.selectProductOne();

jta.append("\n");

dbc.closeDB();

}

});

}

publicvoid viewByAgeCategory(){

ageCategory.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

dbc.makeConnection();

dbc.setHostURL();

dbc.selectProductTwo();

jta.append("\n");

dbc.closeDB();

}

});

}

publicvoid viewByType(){

type.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

dbc.makeConnection();

dbc.setHostURL();

dbc.selectProductThree();

jta.append("\n");

dbc.closeDB();

}

});

}

publicvoid viewByYear(){

year.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

dbc.makeConnection();

dbc.setHostURL();

dbc.selectProductFour();

jta.append("\n");

dbc.closeDB();

}

});

}

publicstaticvoid main(String[] args){

new ViewProductDetails();

}

}

import javax.swing.*;

import java.sql.*;

import java.awt.*;

import java.awt.event.*;

class DBController{

Connection db;

Statement statement;

publicvoid makeConnection(){

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(Exception e){

System.out.println("Problem loading the driver");

}

}

publicvoid setHostURL(){

String url ="jdbc:odbc:VideoLibrary";

closeDB();

try{

db = DriverManager.getConnection(url,"","");

statement = db.createStatement();

DatabaseMetaData dbmd = db.getMetaData();

ResultSet rs = dbmd.getTables(null, null, null,new String[]{"TABLE"});

}

catch(Exception e){

System.out.println("Could not initialise the database");

e.printStackTrace();

}

}

publicvoid selectProductOne(){

try{

ResultSet rs1 = statement.executeQuery("SELECT * FROM Product ORDER BY name");

ResultSetMetaData rsmd1 = rs1.getMetaData();

for(int i = 1; i <= rsmd1.getColumnCount(); i++){

rsmd1.getColumnName(i) +"";

}

while(rs1.next()){

for(int i = 1; i <= rsmd1.getColumnCount(); i++){

rs1.getObject(i) +"";

}

}

}

catch(SQLException e){

e.printStackTrace();

}

}

publicvoid selectProductTwo(){

try{

ResultSet rs2 = statement.executeQuery("SELECT * FROM Product ORDER BY ageCategory");

ResultSetMetaData rsmd2 = rs2.getMetaData();

for(int i = 1; i <= rsmd2.getColumnCount(); i++){

rsmd2.getColumnName(i) +"";

}

while(rs2.next()){

for(int i = 1; i <= rsmd2.getColumnCount(); i++){

rs2.getObject(i) +"";

}

}

}

catch(SQLException e){

e.printStackTrace();

}

}

publicvoid selectProductThree(){

try{

ResultSet rs3 = statement.executeQuery("SELECT * FROM Product ORDER BY type");

ResultSetMetaData rsmd3 = rs3.getMetaData();

for(int i = 1; i <= rsmd3.getColumnCount(); i++){

rsmd3.getColumnName(i) +"";

}

while(rs3.next()){

for(int i = 1; i <= rsmd3.getColumnCount(); i++){

rs3.getObject(i) +"";

}

}

}

catch(SQLException e){

e.printStackTrace();

}

}

publicvoid selectProductFour(){

try{

ResultSet rs4 = statement.executeQuery("SELECT * FROM Product ORDER BY year");

ResultSetMetaData rsmd4 = rs4.getMetaData();

for(int i = 1; i <= rsmd4.getColumnCount(); i++){

rsmd4.getColumnName(i) +"";

}

while(rs4.next()){

for(int i = 1; i <= rsmd4.getColumnCount(); i++){

rs4.getObject(i) +"";

}

}

}

catch(SQLException e){

e.printStackTrace();

}

}

publicvoid closeDB(){

try{

if(statement !=null){

statement.close();

}

if(db !=null){

db.close();

}

}

catch(Exception e){

System.out.println("Could not close the current connection");

e.printStackTrace();

}

}

}

[14649 byte] By [james-mcfaddena] at [2007-11-27 11:40:20]
# 1

What are you going to do? How about learn how to read compiler output? You keep coming here with what looks like different problems, but they're not, they're all basically the same. If you paid attention to how the first one got fixed, you'd be able to fix all the others! Trust me, you would

You can't just keep coming here every time something doesn't compile, you'll get nowhere!

Here's a start: The compiler is telling you that what you've typed as code is not a statement. So look at the bit of code it's complaining about. What do you think that line of code is supposed to do?

georgemca at 2007-7-29 17:31:18 > top of Java-index,Java Essentials,New To Java...
# 2

thanks for the reply. i've got rid of the errors + i put the 2 programs together into 1 new program (shown below). this new program compiles OK. when i run it a frame appears with check boxes, a text area and a button inside it. the text area is smaller than it should be. but when i press one of the check boxes, the following errors appear in the jGRASP console. how do i get rid of these strange errors?

-jGRASP exec: java ViewProductDetails

java.sql.SQLException: Invalid handle

at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)

at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)

at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)

at ViewProductDetails$1.actionPerformed(ViewProductDetails.java:79)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

-jGRASP: process aborted by user.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.sql.*;

public class ViewProductDetails extends JFrame{

JPanel pnlBox, pnlBody, pnlFooter;

JCheckBox name;

JCheckBox ageCategory;

JCheckBox type;

JCheckBox year;

JButton returnToProductMenu;

JTextArea jta;

Container contentpane;

Connection db;

Statement statement;

public ViewProductDetails(){

super("View Product Details");

contentpane = getContentPane();

contentpane.setLayout(new BorderLayout());

pnlBox = new JPanel();

pnlBody = new JPanel();

pnlFooter = new JPanel();

jta = new JTextArea();

jta.setFont(new Font("Serif", Font.PLAIN, 12));

jta.setLineWrap(true);

jta.setWrapStyleWord(true);

jta.setEditable(false);

name = new JCheckBox("Name");

ageCategory = new JCheckBox("Age Category");

type = new JCheckBox("Type");

year = new JCheckBox("Year");

pnlBox.add(name);

pnlBox.add(ageCategory);

pnlBox.add(type);

pnlBox.add(year);

JScrollPane jsp = new JScrollPane(jta);

pnlBody.add(jsp, BorderLayout.CENTER);

returnToProductMenu = new JButton("Return To Product Menu");

pnlFooter.add(returnToProductMenu);

contentpane.add(pnlBox,BorderLayout.NORTH);

contentpane.add(pnlBody,BorderLayout.CENTER);

contentpane.add(pnlFooter,BorderLayout.SOUTH);

pack();

setLocationRelativeTo(null);

setVisible(true);

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(Exception e){

System.out.println("Problem loading the driver");

}

String url = "jdbc:odbc:VideoLibrary";

try{

db = DriverManager.getConnection(url,"","");

statement = db.createStatement();

DatabaseMetaData dbmd = db.getMetaData();

ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"});

}

catch(Exception e){

System.out.println("Could not initialise the database");

e.printStackTrace();

}

name.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

try{

ResultSet rs1 = statement.executeQuery("SELECT * FROM Product ORDER BY name");

ResultSetMetaData rsmd1 = rs1.getMetaData();

for(int i = 1; i <= rsmd1.getColumnCount(); i++){

jta.append(rsmd1.getColumnName(i) + "");

}

jta.append("\n");

while(rs1.next()){

for(int i = 1; i <= rsmd1.getColumnCount(); i++){

jta.append(rs1.getObject(i) + "");

}

jta.append("\n");

}

}

catch(SQLException ea){

ea.printStackTrace();

}

}

});

ageCategory.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

try{

ResultSet rs2 = statement.executeQuery("SELECT * FROM Product ORDER BY ageCategory");

ResultSetMetaData rsmd2 = rs2.getMetaData();

for(int i = 1; i <= rsmd2.getColumnCount(); i++){

jta.append(rsmd2.getColumnName(i) + "");

}

jta.append("\n");

while(rs2.next()){

for(int i = 1; i <= rsmd2.getColumnCount(); i++){

jta.append(rs2.getObject(i) + "");

}

jta.append("\n");

}

}

catch(SQLException eb){

eb.printStackTrace();

}

}

});

type.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

try{

ResultSet rs3 = statement.executeQuery("SELECT * FROM Product ORDER BY type");

ResultSetMetaData rsmd3 = rs3.getMetaData();

for(int i = 1; i <= rsmd3.getColumnCount(); i++){

jta.append(rsmd3.getColumnName(i) + "");

}

jta.append("\n");

while(rs3.next()){

for(int i = 1; i <= rsmd3.getColumnCount(); i++){

jta.append(rs3.getObject(i) + "");

}

jta.append("\n");

}

}

catch(SQLException ec){

ec.printStackTrace();

}

}

});

year.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

try{

ResultSet rs4 = statement.executeQuery("SELECT * FROM Product ORDER BY year");

ResultSetMetaData rsmd4 = rs4.getMetaData();

for(int i = 1; i <= rsmd4.getColumnCount(); i++){

jta.append(rsmd4.getColumnName(i) + "");

}

jta.append("\n");

while(rs4.next()){

for(int i = 1; i <= rsmd4.getColumnCount(); i++){

jta.append(rs4.getObject(i) + "");

}

jta.append("\n");

}

}

catch(SQLException ed){

ed.printStackTrace();

}

}

});

returnToProductMenu.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

setVisible(false);

}

});

try{

if(statement != null){

statement.close();

}

if(db != null){

db.close();

}

}

catch(Exception e){

System.out.println("Could not close the current connection");

e.printStackTrace();

}

}

public static void main(String[] args){

new ViewProductDetails();

}

}

james-mcfaddena at 2007-7-29 17:31:18 > top of Java-index,Java Essentials,New To Java...