Results 1 to 2 of 2
  1. #1
    mainy is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default Driving me insane - Program not working as it should ><


    I have four classes. Select, Login, Connect. I will break the situation down as the total code of my project is about 3000 lines and I doubt you want to shift through all that :p

    Basically, MainGui uses Connect for a database connection. I have something like this set up:

    public class MainGui extends javax.swing.JFrame implements Printable {

    public MainGui() {

    public String url = new String();

    Connect conDatabase = new Connect(url);

    The problem is, when I make a new object of this class in the Select class like so:
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
    MainGui m = new MainGui();
    m.url = "jdbc:mysql://"
    It doesnt work, it cant connect to the database. The reason is, when I create a new Object of MainGui (MainGui m = new MainGui()) it loads the current configuration of MainGui before I can edit the url.

    Is it possible to set the m.url = "addy" before initalising the object?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    One way would be to make the constructor take the url so when you construct you know the url to set. HOWEVER, that is a smell. GUI code should have nothing to do with connecting to databases. And you certainly should not be connecting to the database on the EDT.

Similar Threads

  1. Applet to HTML Driving me bonkers
    By proud2bhaole in forum Java Applets
    Replies: 6
    Last Post: 04-14-2010, 02:08 PM
  2. Working on a menu program...using exceptions
    By Nightwarrior in forum New To Java
    Replies: 0
    Last Post: 04-16-2009, 04:40 AM
  3. Replies: 2
    Last Post: 03-16-2009, 08:52 PM
  4. Loop driving me loopy!!!!!
    By soc86 in forum New To Java
    Replies: 8
    Last Post: 01-16-2009, 02:00 AM
  5. My program is not working
    By MICHAELABICK in forum New To Java
    Replies: 6
    Last Post: 12-23-2008, 12:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts