package code;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ModifyRecord extends JFrame {
JLabel label_1;
JLabel label_2;
JLabel itemLbl;
JComboBox supplierCB;
JComboBox itemCB;
JButton getRecordBtn;
JButton closeBtn;
Connection con;
String supplier,item;
public ModifyRecord()
{
supplier="";
item="";
}
public ModifyRecord(final Connection con)
{
super("Select supplier and item name");
this.con=con;
ModifyRecordLayout customLayout = new ModifyRecordLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout);
Font fontB=new Font("Verdana", Font.BOLD,16);
label_1 = new JLabel("Select Fields");
label_1.setFont(fontB);
getContentPane().add(label_1);
fontB=new Font("Verdana", Font.BOLD,14);
label_2 = new JLabel("Supplier Name");
label_2.setFont(fontB);
getContentPane().add(label_2);
itemLbl = new JLabel("Item Name");
itemLbl.setFont(fontB);
getContentPane().add(itemLbl);
Font font=new Font("Verdana", Font.PLAIN,14);
supplierCB = new JComboBox();
supplierCB.setFont(font);
supplierCB.setEditable(true);
SupplierSearchBoxModel ssb= new SupplierSearchBoxModel(supplierCB,con);
supplierCB.setModel(ssb);
supplierCB.addItemListener(ssb);
getContentPane().add(supplierCB);
itemCB = new JComboBox();
itemCB.setFont(font);
//we need it to be editable!!
itemCB.setEditable(true);
getContentPane().add(itemCB);
// getContentPane().add(itemCB);
supplierCB.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
supplier=(String) supplierCB.getSelectedItem();
//create the model
ItemSearchBoxModel isb = new ItemSearchBoxModel(itemCB,con,supplier);
//set the model on the combobox
itemCB.setModel(isb);
//set the model as the item listener also
itemCB.addItemListener(isb);
itemCB.setEditable(true);
repaint();
}
});
//create the combobox
getRecordBtn = new JButton("GetRecord");
getRecordBtn.setFont(fontB);
getRecordBtn.setActionCommand("getRecord");
getRecordBtn.addActionListener(btnListener);
getContentPane().add(getRecordBtn);
closeBtn = new JButton("Close");
closeBtn.setFont(fontB);
closeBtn.setActionCommand("close");
closeBtn.addActionListener(btnListener);
getContentPane().add(closeBtn);
setSize(getPreferredSize());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
ActionListener btnListener=new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String srcObject = e.getActionCommand();
if(srcObject=="getRecord")
{
supplier=(String) supplierCB.getSelectedItem();
item=(String) itemCB.getSelectedItem();
dispose();
}
else if(srcObject=="close")
{
dispose();
}
}
};
public String getSupplier()
{
return supplier;
}
public String getItem()
{
return item;
}
public static void main(String args[]) {
ModifyRecord window = new ModifyRecord();
window.setTitle("ModifyRecord");
window.pack();
window.show();
}
}
class ModifyRecordLayout implements LayoutManager {
public ModifyRecordLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 353 + insets.left + insets.right;
dim.height = 222 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+40,insets.top+8,256,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+56,88,32);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+104,88,32);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+56,176,32);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+104,176,32);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+152,136,32);}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+152,128,32);}
}
}