Hi everyone,
i tried to do 2 operations on a database table; insert and delete. There are several textfields requesting name, lastname etc. When these fields are filled, it should insert the data to the appropriate columns of a row in the table. Delete should delete the current row elements in the table.The code is below, any ideas? i tried to do a seperate class just to connect and to the operations but it got a bit messed up.
public class DBGUIMain extends JPanel {
private JTextField[] fields;
// Create a form with the specified labels, tooltips, and sizes.
public DBGUIMain(String[] labels, char[] mnemonics,
int[] widths, String[] tips) {
super(new BorderLayout());
JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1));
JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1));
JPanel buttonPanel = new JPanel(new GridLayout(labels.length, 1));
add(labelPanel, BorderLayout.WEST);
add(fieldPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
fields = new JTextField[labels.length];
for (int i=0; i < labels.length; i+=1) {
fields = new JTextField();
if (i < tips.length) fields.setToolTipText(tips);
if (i < widths.length) fields.setColumns(widths);
JLabel lab = new JLabel(labels, JLabel.RIGHT);
lab.setLabelFor(fields);
if (i < mnemonics.length) lab.setDisplayedMnemonic(mnemonics);
labelPanel.add(lab);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
p.add(fields);
fieldPanel.add(p);
}
}
public String getText(int i) {
return( fields.getText() );
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
String[] labels = { "First Name", "Last Name", "Birth Date", "Last Logon Date" , "ONLINE(y/n)?"};
char[] mnemonics = { 'F', 'S', 'B', 'L' , 'O'};
int[] widths = { 15, 15, 15, 15, 5 };
String[] descs = { "First Name", "Last Name", "Birth Date", "Last Logon Date" , "ONLINE(y/n)??" };
final DBGUIMain form = new DBGUIMain(labels, mnemonics, widths, descs);
JButton insert = new JButton("INSERT");
JButton delete = new JButton("DELETE");
insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("INSERT");
}
}
);
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("DELETE");
}
}
);
JFrame f = new JFrame("Text Form Example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(form, BorderLayout.NORTH);
JPanel p = new JPanel();
p.add(insert);
p.add(delete);
f.getContentPane().add(p, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
}
i tried to do 2 operations on a database table; insert and delete. There are several textfields requesting name, lastname etc. When these fields are filled, it should insert the data to the appropriate columns of a row in the table. Delete should delete the current row elements in the table.The code is below, any ideas? i tried to do a seperate class just to connect and to the operations but it got a bit messed up.
public class DBGUIMain extends JPanel {
private JTextField[] fields;
// Create a form with the specified labels, tooltips, and sizes.
public DBGUIMain(String[] labels, char[] mnemonics,
int[] widths, String[] tips) {
super(new BorderLayout());
JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1));
JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1));
JPanel buttonPanel = new JPanel(new GridLayout(labels.length, 1));
add(labelPanel, BorderLayout.WEST);
add(fieldPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
fields = new JTextField[labels.length];
for (int i=0; i < labels.length; i+=1) {
fields = new JTextField();
if (i < tips.length) fields.setToolTipText(tips);
if (i < widths.length) fields.setColumns(widths);
JLabel lab = new JLabel(labels, JLabel.RIGHT);
lab.setLabelFor(fields);
if (i < mnemonics.length) lab.setDisplayedMnemonic(mnemonics);
labelPanel.add(lab);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
p.add(fields);
fieldPanel.add(p);
}
}
public String getText(int i) {
return( fields.getText() );
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
String[] labels = { "First Name", "Last Name", "Birth Date", "Last Logon Date" , "ONLINE(y/n)?"};
char[] mnemonics = { 'F', 'S', 'B', 'L' , 'O'};
int[] widths = { 15, 15, 15, 15, 5 };
String[] descs = { "First Name", "Last Name", "Birth Date", "Last Logon Date" , "ONLINE(y/n)??" };
final DBGUIMain form = new DBGUIMain(labels, mnemonics, widths, descs);
JButton insert = new JButton("INSERT");
JButton delete = new JButton("DELETE");
insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("INSERT");
}
}
);
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("DELETE");
}
}
);
JFrame f = new JFrame("Text Form Example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(form, BorderLayout.NORTH);
JPanel p = new JPanel();
p.add(insert);
p.add(delete);
f.getContentPane().add(p, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
}