import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Appointment_Form extends JFrame {
//private static final String = null;
private String pet;
private String c_id;
private String check_in;
private String check_out;
private String diagnosis;
protected Object Appointment_Form;
public Appointment_Form(){
Appointment_Form ();
}
public void Appointment_Form (){
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(7, 1));
p1.add(new JLabel("Pet: "));
p1.add(new JLabel("C_ID: "));
p1.add(new JLabel("Check_in: "));
p1.add(new JLabel("Check_out: "));
p1.add(new JLabel("Diagnosis: "));
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(6, 1));
p2.add(new JTextField(15));
p2.add(new JTextField(15));
p2.add(new JTextField(15));
p2.add(new JTextField(15));
p2.add(new JTextField(15));
JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(1, 3));
p3.add(new JLabel(""));
JButton add_btn;
p3.add(add_btn = new JButton("Calendar"));
p3.add(add_btn = new JButton("Cancel"));
JButton list_btn;
p3.add( list_btn = new JButton("Next"));
JPanel p4 = new JPanel(new BorderLayout());
p2.setLayout(new GridLayout(7, 2));
p4.add(p1, BorderLayout.WEST);
p4.add(p2, BorderLayout.CENTER);
p4.add(p3, BorderLayout.SOUTH);
/* p4.add(new JButton("Calendar"),BorderLayout.WEST);
p4.add(new JButton("Cancel"),BorderLayout.CENTER);
p4.add(new JButton("Next"),BorderLayout.EAST);*/
add(p4, BorderLayout.WEST);
add_btn.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
/*{
if(e.getSource()== Appointment_Form)
{
try{
System.out.println("Loading the driver...");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Establishing a connection...");
Connection conne = DriverManager.getConnection("jdbcdbcetSystem_DSN");
System.out.println("a success!");
//Get statement from the connection
Statement state = (Statement) conne.createStatement();
//Execute statement
String Query ="select "
}
}
}
);*/
list_btn.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}
);
}
public static void main(String[]args){
new Calendar1();
Appointment_Form frame = new Appointment_Form();
frame.setTitle("Appointment Form");
frame.setSize(360, 370);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
}
public String getPet();{
return getPet();
}
public void setPet(String pet);{
this.pet = pet;
}
public String getC_id();{
return c_id;
}
public void setC_id(String c_id);{
this.c_id = c_id;
}
public String getCheck_in();{
return getCheck_in();
}
public void setCheck_in(String check_in);{
this.check_in = check_in;
}
public String getCheck_out();{
return getCheck_out();
}
public void setCheck_out(String check_out );{
this.check_out = check_out;
}
public String getDiagnosis();{
return getDiagnosis();
}
public void setDiagnosis(String diagnosis);{
this.diagnosis = diagnosis;
}
}
It is a bad idea to have an object name that is the same as either a standard java class name or the name of a java class that you use. The fact that you also have a method called Appointment_Form doesn't help either.
The getSource() method will return the Object upon which the event initially occurred. (i.e. the button)
However, you will have to make your JButton final to refer to it in the ActionListener or you will have to make the JButton a class variable rather than a variable local to the constructor.
(Also, I might add, that the getSource() method is more useful when you have the same ActionListener is added to several buttons. Then, you'd use it to figure out which one fired the ActionListener so you'd know how to respond. With your anonymous ActionListener, unless you've added the button's actionListener to another Button as well, the only source that can fire it is the button that you added it to.)