Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Congratulations on a brilliant idea and a great site..."

Geography

Where in the world do Tek-Tips members come from?

DIRE STRAIGHTS -- NEED HELP ASAP!!!

ceaton (MIS)
4 Dec 99 17:26
I'm in need of some help rather fast, project due!!

I am so new to java and I have this project due and the boss is breathing down our necks, anyway I need to know how to call some classes. I have this button on an applet from which I need to trigger the following class.

void va_MouseClicked(java.awt.event.MouseEvent event)
{
I need to pass a string or label to my class.
}


This is my query class, now I need to make several of these, I'm just not sure how to put all three of my class to work together. I think I'm really missing something here, just not sure what.


import java.awt.*;
import java.io.*;
import java.sql.*;
import java.net.URL;

public class BRR extends Object {
JVRConn conn;

public BRR(JVRConn _conn) {

conn = _conn;

String specLiab;
PreparedStatement prepstmt;

// the labelspecliab is what I need to retrieve from my button,
// I can either pass this as a label or string.

specLiab = ces.labelspecliab.getText().toString();

try {
boolean found = false;
prepstmt = JVRConn.theConn.dbConn.prepareStatement
("SELECT BRR FROM LIAB WHERE TEXT = ?");
prepstmt.setString(1, specLiab);


ResultSet rs;
rs = prepstmt.executeQuery();

found = rs.next();
if (found)
System.out.println(rs.getString(1));
else
System.out.println("Not here" + specLiab + ");
prepstmt.close();
}
catch(Exception e ) {
e.printStackTrace();
}
}

}

This is my class to make the connection to my db. I know this is correct. I can't just put them together.

import java.net.URL;
import java.sql.*;

class JVRConn {
static myConnection theConn;

public static void main (String args[]) {
theConn = new myConnection();
theConn.Connect2Db("JVR", " ", " ");
}
}

class myConnection {
Connection dbConn = null;
void Connect2Db(String db, String user, String passw) {
try {
// using the driver
Driver d =
(Driver)Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
// URL corresponding to the ODBC DSN
String URL = "jdbc:odbc:" + db;
// DB logon
dbConn =
DriverManager.getConnection(URL, user, passw);
}
catch (Exception e) {
e.printStackTrace();
}
}

void Disconnect2Db() {
try {
dbConn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Courtney
ceaton@lrp.com

tpena (Programmer)
5 Dec 99 12:15
First, here is my understanding of your situation:

You have some sort of gui/applet with a button (or set of) that each has a label. When the user clicks on one of these buttons, you want to receive the button pressed event and create the SQL statement using the text of the label of the button that was pressed. Also, since you only include java.awt.*, I am assuming you are not using Swing.


First you do not need a MouseClicked routine. It wouldn't help you anyway since mouse clicks are registered on the gui and not just over a button. Second, don't inherit your class from java.lang.Object because ALL Java objects automatically inherit from Object.

Well given the structure of your code, it would probably be easiest to make your BRR class implement java.awt.event.ActionListener. A class which implements ActionListener signals that it is willing to handle GUI events. For this to function, you need to implement the function <public void actionperformed(java.awt.event.Event e)> in your BRR class.

Then wherever you create your GUI (I don't see any GUI code here), set the action listener for the button (button.addActionListener(<the object which implements ActionListener>). This of course means that you will have to move the SQL Connection code out from the constructor to another function and call it once you have the button name.

I wrote a small, simple GUI which shows how you can create a button and set the action listener.

*********************************
import java.awt.*;
import java.awt.event.*;


public class ClickMe implements ActionListener {

Frame frame;
TextArea area;

public ClickMe() {
frame = new Frame();
area = new TextArea();

Button button = new Button("ClickMe");

button.addActionListener(this);

frame.add(button, BorderLayout.NORTH);
frame.add(area, BorderLayout.SOUTH);

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

frame.pack();
frame.setVisible(true);
}


public void actionPerformed(ActionEvent e) {
area.setText(e.getActionCommand() + "\n");
}

public static void main(String[] args) {
ClickMe c = new ClickMe();
}
}
*********************************

This compiles with JDK1.1 and only uses AWT components.

Hoepfully this can get you started in the right direction.

tito

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close