
i need to add JTable into this code pls help me..
package Com; import Com.Details; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; @SuppressWarnings("serial") public class AddPage extends JFrame {
JDesktopPane pane = new JDesktopPane(); static Details details= new Details();
JTextField searcharea;
String str;
{ setLayout(null);
setTitle("Employee Details Application");
JButton add=new JButton("ADD NEW");
JButton edit=new JButton("EDIT");
JButton delete=new JButton("DELETE");
JButton save=new JButton("SAVE");
JButton cancel=new JButton("CANCEL");
JButton close=new JButton("CLOSE");
JButton print=new JButton("PRINT");
add.setBounds(10,40,100,40);
edit.setBounds(120,40,100,40);
delete.setBounds(240,40,100,40);
save.setBounds(360,40,100,40);
cancel.setBounds(480,40,100,40);
close.setBounds(600,40,100,40);
print.setBounds(720,40,100,40);
add(add);
add(edit);
add(save);
add(delete);
add(cancel);
add(close);
add(print);
String[] search={"--search by--","Employee_ID","Employee Name"};
final JComboBox box=new JComboBox(search);
box.setBounds(10,120,100,25);
add(box);
searcharea=new JTextField();
searcharea.setBounds(130,120,150,25);
add(searcharea);
JButton submit=new JButton("SUB");
submit.setBounds(300,125,80, 20);
add(submit);
details.setBounds(100,60,1300,600);
add(pane);
//Action Listener for button
//for adding new details
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
AddPage addpage=new AddPage();
addpage.add(details);
//EmployeeMain empmain=new EmployeeMain();
//empmain.main(null);
}
});
/*for editing previous details
edit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
AddPage addpage=new AddPage();
addpage.add(details);
System.out.println("edit carefully");
}
}); */
//for saving
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
details.insert();
//EmployeeMain empmain=new EmployeeMain();
//empmain.main(null);
System.out.println("saved successfully");
}
});
//action area for search area.
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String selecteditem=(String) box.getSelectedItem();
if(selecteditem=="Employee_ID"){
Employee employee=new Employee();
String emp=searcharea.getText();
AddPage addpage=new AddPage();
addpage.add(details);
details.setEmpID(emp);
}
else if(selecteditem=="Employee Name"){
Employee employee=new Employee();
String emp=searcharea.getText();
AddPage addpage=new AddPage();
addpage.add(details);
details.setEmpName(emp);
}
}
});
//end action listener
//table addition
setVisible(true); setSize(1250,1000);
} public static void main(String[] args) { new AddPage(); //addpage.add(details); // addpage.add(table);
} }
Thanks in advance.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.