talyu 0 Newbie Poster

Hi I am the stupid girl again..>< forget about the previous reply..mayb i should make myself abit more clear...this is what i want to have eg

entry field:
From:----------(user enter)
To:-------------(user enter)

then it read what the use typed (eg SW1 and SE1) then it search my DB for SW1 and SE1 and return the x and y co ordinates of SW1 and SE1. then it do the pythagorus on those x and y co ordinates..

is this very wrong?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.EventObject;
public class distancesystem extends JPanel
{ private JLabel fromLabel; 
  private JTextField fromField; 
  private JLabel toLabel;
  private JTextField toField;  
   
  public CreateDialogPanel()
  { /* Create subcomponents: */
    fromLabel = new JLabel("From:"); 
    fromField = new JTextField(); 
    toLabel = new JLabel("To:");
    toField = new JTextField();
     
    setBorder(
      BorderFactory.createTitledBorder("Create fields")); 
       
    add(fromLabel);      // Add the subcomponents in 
    add(fromField);      // the order they should appear
    add(toLabel);   // in the dialog. 
    add(toField);
  
  }
  public void setOldFields(Varchar from, Varchar to,
                                       )
  { fromField.setText(from); 
    toField.setText(to);
     
  }
  public Dimension getPreferredSize()
  { return new Dimension(400,120); }
  public Dimension getMinimumSize()
  { return new Dimension(400,120); }
  /* Customised layout method, fixed positions
    (xstart,ystart,width,height) for components: */
  public void doLayout()
  { nameLabel.setBounds(10,10,90,30);
    nameField.setBounds(100,15,270,20);
    addressLabel.setBounds(10,40,90,30);
    addressField.setBounds(100,45,270,20);
    phoneLabel.setBounds(10,70,90,30);
    phoneField.setBounds(100,75,270,20); 
  }
  public void reset()
  { fromField.setText(""); 
    toField.setText("");
   
  }
  public String getFrom() 
  { return fromField.getText(); } 
  public String getTo()
  { return toField.getText(); }
}
public class DistanceCalculationSystem extends JDialog
{ private JPanel bottom; /* Contains buttons: */
  private JButton okButton, cancelButton;
/* …
talyu 0 Newbie Poster

OK~ so mayb like this? Sorry i seems so stupid...but i really wanna get it working...>.< really appreciate your help

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.EventObject;
import java.io.*;
import java.sql.*;
public class DistanceCalculationSystem extends JDialog
{ private JPanel bottom; /* Contains buttons: */
  private JButton okButton, cancelButton;
/* The panel with the entry fields: */
  private CreateDialogPanel dialogPanel;
  private String defaultFrom = ""; 
  private String defaultTo = "";
  
  private String newFrom; 
  private String newTo;
     
  public EntryCreateDialog(JFrame owner)
  { 
    super(owner, "Distance Calculating system", true);
  /* Create the subcomponents: */
    okButton = new JButton("GetDistance");
    cancelButton = new JButton("Cancel");
  /* Instance of nested 
   * class for event handling: */
    ButtonHandler bHandler = new ButtonHandler();
    GetDistanceButton.addActionListener(bHandler);
    cancelButton.addActionListener(bHandler);
      
    bottom = new JPanel();
    bottom.add(GetDistanceButton);      // Uses the implicit flow
    bottom.add(cancelButton);  // layout of JPanel. 
    
    bottom.setBorder(
        BorderFactory.createEtchedBorder());
    dialogPanel = new CreateDialogPanel();
  /* Dialog is given a Border Layout: */
    getContentPane().setLayout(new BorderLayout());
  /* Put button panel at base of dialog: */    
    getContentPane().add(bottom, 
                         BorderLayout.SOUTH); 
    getContentPane().add(dialogPanel, 
                         BorderLayout.CENTER); 
  }
  public void setOldFields(Varchar from, Varchar to)
{ defaultFrom = from;
  defaultTo = to;
  dialogPanel.setOldFields(from,to); 
 
}
 public static void main(string[] args)
 { ConsoleReader in = new ConsoleReader(System.in);
 
 var v1 = in.readVar;
 var v2 = in.readVar;
public void setFields(Varchar from, Varchar to)
{ newFrom = from; 
  newTo = to;
 
}
 
public String getFrom() 
{ return newFrom; } 
public String getTo() 
{ return newTo; }

class ButtonHandler 
implements ActionListener
{ public void actionPerformed(ActionEvent ev)
  { JButton button = (JButton) ev.getSource();
    String label = button.getText();
    if ("GetDistance".equals(label))
    
class customersDB …
talyu 0 Newbie Poster

Hi ~ I have done this so far....a entryfield for user to type in the TO and FROM postcode, then I connect to the sql database...but I still cant find out how to READ the X and Y from the sql table then calculate using them..I got the table in database set up...a table of postcodeand its x and y points. Please help~ appreciate alot

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.EventObject;
import java.io.*;
import java.sql.*;
public class EntryCreateDialog extends JDialog
{ private JPanel bottom; /* Contains buttons: */
  private JButton okButton, cancelButton;
/* The panel with the entry fields: */
  private CreateDialogPanel dialogPanel;
  private String defaultFrom = ""; 
  private String defaultTo = "";

  private String newFrom; 
  private String newTo;

  public EntryCreateDialog(JFrame owner)
  { 
    super(owner, "Distance Calculating system", true);
  /* Create the subcomponents: */
    okButton = new JButton("GetDistance");
    cancelButton = new JButton("Cancel");
  /* Instance of nested 
   * class for event handling: */
    ButtonHandler bHandler = new ButtonHandler();
    GetDistanceButton.addActionListener(bHandler);
    cancelButton.addActionListener(bHandler);

    bottom = new JPanel();
    bottom.add(GetDistanceButton);      // Uses the implicit flow
    bottom.add(cancelButton);  // layout of JPanel. 

    bottom.setBorder(
        BorderFactory.createEtchedBorder());
    dialogPanel = new CreateDialogPanel();
  /* Dialog is given a Border Layout: */
    getContentPane().setLayout(new BorderLayout());
  /* Put button panel at base of dialog: */    
    getContentPane().add(bottom, 
                         BorderLayout.SOUTH); 
    getContentPane().add(dialogPanel, 
                         BorderLayout.CENTER); 
  }
  public void setOldFields(Varchar from, Varchar to)
{ defaultFrom = from;
  defaultTo = to;
  dialogPanel.setOldFields(from,to); 
}
public void setFields(Varchar from, Varchar to)
{ newFrom = from; 
  newTo = to;

}

public String getFrom() 
{ return newFrom; } 
public String getTo() 
{ …
talyu 0 Newbie Poster

wowoooooooooo thanks!!!! so clever!!!!!!!!! so thats not hard at all yeah?? connecting SQL and java and transfering to and from

talyu 0 Newbie Poster

HI guys, your code is soooo amazing~ i am doing something similar too but kinda stuck hope you can help me pleaseeee.basically i am also calculating the distance, but instead of having all the co ordinates typed in a text file, i am having a fill in blank for user to fill in the TO and FORM then i want it to search through my SQL database to find the matching co ordinates. for example user fill in TO: SE1 FROM SW5, then it will search the database to find the co ordinates of SE1 and SW 5 then cauculate. is that possible??? please help~ i was searching all night but no clue.

talyu 0 Newbie Poster

CAN YOU BE ABIT MORE SPECIFIC ON THIS PLEASE? I AM SORRY I AM QUITE NEW BUT I AM VERY INTERESTED..PLEASE~
:eek:

OPEN THE TEXT FILE FOR WRITE
OPEN THE DATABASE
QUERY THE DATABASE
CALL mysql_field_count() TO SEE IF THE QUERY RETURNED A RESULT SET
FOR EACH RESULTSET ROW (one of the mysql_fetch??? functions)
   WRITE RESULT ROW TO TEXT FILE

CLOSE THE DATABASE
CLOSE THE TEXT FILE

You need to be familiar with the mysql docs if you want to write a program that queries a mysql database.