• Post Reply Bookmark Topic Watch Topic
  • New Topic

import error  RSS feed

 
Donna Harrington
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I wonder could anybody help me.I have a searchCustomer class which I can enter customers Id or first name or last name in the JTextFields and then click on the search button which brings me to another JPanel which has the customers details labels but i dont know how to bring the data entered in the JTextField in the 1st Panel to the 2nd Panel and display all the customers details in JLabels. I have the GUI done for the 1st and 2nd Panels but i cannot find the code to display the customers details in the 2nd panel.
Also i have "import searchCustomer;" at the top of my displayCustDetails panel to join them but when i compile displayCustDetails it gives me the error
displayCustDetails.java [11:1] '.' expected
import searchCustomer;
^
I hope somebody can see what the problem is.
Thanx alot.
Donna.
Ps.Here is my code for searchCustomer :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import java.sql.*;

public class searchCustomer extends JPanel implements ActionListener {
JPanel p1, custOpt, cards, box;
CardLayout cl;
JLabel newLabel;
JButton button;
Connection conn;
static String custId=new String();
static JButton searchC;
String cFname,cLname;

JTextField custIdTF ,custFNameTF ,custLNameTF;

public searchCustomer(CardLayout cl, JPanel p) {//Constructor for add employee
setSize(500,500);
this.cl = cl;
cards = p;

box = new JPanel();
box.setSize(200,200);
p1 = new JPanel();
p1.setLayout(new GridLayout(0,2));

JLabel custIdLabel = new JLabel("Customer Id");
custIdTF = new JTextField(20);
p1.add(custIdLabel);
p1.add(custIdTF);

JLabel fNameLabel = new JLabel("First Name");
custFNameTF = new JTextField(20);
p1.add(fNameLabel);
p1.add(custFNameTF);

JLabel lNameLabel = new JLabel("Last Name");
custLNameTF = new JTextField(20);
p1.add(lNameLabel);
p1.add(custLNameTF);


button =new JButton("Main Menu");
button.setActionCommand("pic");
button.addActionListener(this);
p1.add(button);
searchC = new JButton("SEARCH");
searchC.setActionCommand("SEARCH");
searchC.addActionListener(this);
p1.add(searchC);
connect();
//select();
add(p1);
}

public void connect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
System.out.println("Error creating class: "+e.getMessage());
e.printStackTrace();
return;
}
}


/*public void clear(){
custIdTF.setText("");
custFNameTF.setText("");
custLNameTF.setText("");

}*/

public void select()
{
try
{
Connection conn = DriverManager.getConnection("jdbc dbc:acidmenuDatabase","","");
Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery( "SELECT * WHERE custId = '"+custId+" 'OR cFname ='"+cFname+ " 'OR cLname =' " +cLname+"';");
//ResultSetMetaData meta = rs.getMetaData();
//int iColumns = meta.getColumnCount();
}
catch(Exception e){
System.err.println("Problems connecting to database");
e.printStackTrace();
return;
};
}


/*if (rs.next() )
{
employeeIDTF.setText(rs.getString("max"));
}
//stmt.close();
//conn.close();
//}
pstmt.setString(1,custId);
pstmt.setString(2,cFname);
pstmt.setString(3,cLname);
pstmt.executeUpdate();
System.out.println("a bit further");
pstmt.close();
conn.close();
}

catch(Exception e){
System.err.println("Problems connecting to database");
e.printStackTrace();
return;
}
}
*/
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
cl = (CardLayout)(cards.getLayout());
cl.show(cards,command );


if (command.equals("SEARCH") )
{

custId = custIdTF.getText().trim();
cFname = custFNameTF.getText().trim();
cLname = custLNameTF.getText().trim();


connect();
// clear();
JOptionPane.showConfirmDialog( this, "Searching the System", "ACID Systems", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE );
cl.show(cards,"Display Customer");
}
};

public static String getAccountNumber(){
return custId;
}
}

And here is my code for displayCustDetails:
import searchCustomer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import java.sql.*;
public class displayCustDetails extends JPanel implements ActionListener {

JPanel p1, custOpt, cards, box;
CardLayout cl;
JLabel newLabel;
JButton searchCust,modifyCust,deleteCust;
String custId,cSex,cFname,cLname,cDob,cAddress,cContactNo;
JTextField custIdTF ,custSexTF,custFNameTF ,custLNameTF,custDateOfBirthTF ,custAddressTF,custContactNumberTF;


public displayCustDetails(CardLayout cl, JPanel p) {//Constructor for add employee
setSize(500,500);
this.cl = cl;
cards = p;

//String name=searchCustomer.getAccountNumber();
//System.out.println(name);

box = new JPanel();
box.setSize(200,200);
p1 = new JPanel();
p1.setLayout(new GridLayout(0,2));
JLabel customerIdLabel = new JLabel("Customer Id number:");
JLabel custIdLabel = new JLabel(" ");
p1.add(customerIdLabel);
p1.add(custIdLabel);

JLabel sexLabel = new JLabel("Sex");
JLabel custSex = new JLabel(" ");
p1.add(sexLabel);
p1.add(custSex);


JLabel custFNameLabel = new JLabel("First Name");
JLabel custFName = new JLabel(" ");
p1.add(custFNameLabel);
p1.add(custFName);
JLabel custLNameLabel = new JLabel("Last Name");
JLabel custLName = new JLabel(" ");
p1.add(custLNameLabel);
p1.add(custLName);

JLabel cDateOfBirthLabel = new JLabel("Date of Birth");
JLabel custDateOfBirth = new JLabel(" ");
p1.add(cDateOfBirthLabel);
p1.add(custDateOfBirth);
JLabel cAddressLabel = new JLabel("Address");
JLabel custAddress = new JLabel(" ");
p1.add(cAddressLabel);
p1.add(custAddress);

JLabel cContactNumberLabel = new JLabel("Contact Number");
JLabel custContactNumber = new JLabel(" ");
p1.add(cContactNumberLabel);
p1.add(custContactNumber);


//setLayout(new FLowLayout(FlowLayout.LEFT));


JButton modifyCust = new JButton("Modify");
//modifyCust.addActionCommand("Modify");
modifyCust.addActionListener(this);
p1.add(modifyCust);


JButton clearCust = new JButton("Clear");
//clearCust.addActionCommand("Clear");
clearCust.addActionListener(this);
p1.add(clearCust);

JButton deleteCust = new JButton("Delete");
//deleteCust.addActionCommand("Delete");
deleteCust.addActionListener(this);
p1.add(deleteCust);

JButton backButton =new JButton("Main Menu");
backButton.setActionCommand("pic");
backButton.addActionListener(this);
p1.add(backButton);


add(p1);
}

public void actionPerformed(ActionEvent e) {

String command = e.getActionCommand();
cl = (CardLayout)(cards.getLayout());
cl.show(cards,command );
System.out.println(command);

if (command.equals("Modify"))
{
try{
Connection conn;
conn = DriverManager.getConnection("jdbc dbc:acidmenuDatabase","","");
Statement statement = conn.createStatement();


if(custIdTF.getText().equals("")){
String query = "UPDATE customer SET "+ "custId='" + custIdTF.getText()+"',cSex='" + custSexTF.getText() + "',cFname='" + custFNameTF.getText() + "',cLname='" + custLNameTF.getText() + "', cDOB='" + custDateOfBirthTF.getText()+"', cAddress='" + custAddressTF.getText() +"',cContactNumber='" + custContactNumberTF.getText();

int result = statement.executeUpdate(query);

if(result ==1)
System.out.println("\nUpdate successful\n");
JOptionPane.showConfirmDialog( this, "Customer Details are updated to the System", "ACID Systems", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE );
}
else{
System.out.println( "\nUpdate failed\n");


}}
catch(SQLException sqlex){
System.err.println("Problems connecting to database");
sqlex.printStackTrace();
return;

}
}
if(command.equals("Clear"))
{
custIdTF.setText( "");
custSexTF.setText( "");
custFNameTF.setText( "");
custLNameTF.setText( "");
custDateOfBirthTF.setText( "");
custAddressTF.setText( "");
custContactNumberTF.setText( "");
}

if(command.equals("Delete"))
{
try{
Connection conn;
conn = DriverManager.getConnection("jdbc dbc:acidmenuDatabase","","");
Statement statement = conn.createStatement();


if(custIdTF.getText().equals("")){
//String ID = custId1.getText().trim();
String query = "DELETE FROM Customer ( '" + custId + "', '" + cSex + "', '" + cFname + "', '" + cLname + "', '" + cDob + "', '" + cContactNo + "' );";

int result = statement.executeUpdate(query);

if(result ==1)
System.out.println("\nDeletion successful\n");
JOptionPane.showConfirmDialog( this, "Customer Removed from System", "ACID Systems", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE );
}
else{
System.out.println( "\nDeletion failed\n");


}}
catch(SQLException sqlex){
System.err.println("Problems connecting to database");
sqlex.printStackTrace();
return;

}
}
}
}

Sorry for the long code!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not legal Java to import a class from the default package (i.e., the package with no name, where classes are put if you don't use a "package" statement.) This was once legal, actually. I don't recall when this change was made, but it was some years ago.
In any event, it looks as if all of your classes are together in the default package (i.e., not in a package). Two classes in the same package do not need import statements to refer to each other. The purpose of a statement like
import java.io.IOException;
is just to let the compiler know that when you say "IOException" you mean "java.io.IOException". By default, the Java compiler will look for an unqualified class name in the same package as the class being compiled -- so the imports are unnecessary. Remove the statement the compiler is flagging, and you should be all set.
 
Donna Harrington
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Ernest Friedman-Hill.
U've made my day!
x
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!