I have an array holding an address, line 1 and line 2 of the address.
I want to add the array to a Jtable when a btn is clicked. I have read documentation and I am still not getting it please help me.
import java.awt.*;
import java.awt.event.*;
import java.awt.EventQueue;
import javax.swing.*;
public class Driver extends Family {
private JFrame f;
private JPanel p;
JButton btn1 = new JButton("Business Shipping");
JButton btn2 = new JButton("Family Shipping");
JLabel lbl1 = new JLabel("Business Name:");
JLabel lbl2 = new JLabel("URL:");
JLabel lbl3 = new JLabel("Professional Name");
JLabel lbl4 = new JLabel("First Name:");
JLabel lbl5 = new JLabel("Last Name:");
JLabel lbl6 = new JLabel("Email:");
JLabel lbl7 = new JLabel("Phone:");
JLabel lbl8 = new JLabel("Relationship:");
JLabel lbl9 = new JLabel("Answer Call:");
JTextField jt1 = new JTextField(businessName);
JTextField jt2 = new JTextField(website);
JTextField jt3 = new JTextField (toString());
JTextField jt4 = new JTextField(First());
JTextField jt5 = new JTextField(Last());
JTextField jt6 = new JTextField(Email());
JTextField jt7 = new JTextField(Phone());
JTextField jt8 = new JTextField(Relationship());
String txt = Boolean.toString(AnswerCall(Relationship()));//converting boolean to string value
JTextField jt9 = new JTextField(txt);
JTable tbl1 = new JTable();
public Driver () {
gui();
}
btn1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn1MouseClicked(evt);
tbl1.setText(ShippingLabel(sl));
}
});
public void gui() {
f = new JFrame("Address Book");
p = new JPanel();
f.add(p);
p.setLayout(null);
p.add(btn1);
p.add(btn2);
p.add(tbl1);
p.add(lbl1);
p.add(lbl2);
p.add(lbl3);
p.add(lbl4);
p.add(lbl5);
p.add(lbl6);
p.add(lbl7);
p.add(lbl8);
p.add(lbl9);
p.add(jt1);
p.add(jt2);
p.add(jt3);
p.add(jt4);
p.add(jt5);
p.add(jt6);
p.add(jt7);
p.add(jt8);
p.add(jt9);
lbl1.setLocation(27, 20);
lbl2.setLocation(27, 40);
lbl3.setLocation(27, 60);
lbl4.setLocation(27, 80);
lbl5.setLocation(27, 100);
lbl6.setLocation(27, 120);
lbl7.setLocation(27, 140);
lbl8.setLocation(27, 160);
lbl9.setLocation(27, 180);
btn1.setLocation(27, 200);
btn2.setLocation(27, 220);
jt1.setLocation(223, 20);
jt2.setLocation(223, 40);
jt3.setLocation(223, 60);
jt4.setLocation(223, 80);
jt5.setLocation(223, 100);
jt6.setLocation(223, 120);
jt7.setLocation(223, 140);
jt8.setLocation(223, 160);
jt9.setLocation(223, 180);
tbl1.setLocation(223, 200);
lbl1.setSize(230, 20);
lbl2.setSize(230, 20);
lbl3.setSize(230, 20);
lbl4.setSize(230, 20);
lbl5.setSize(230, 20);
lbl6.setSize(230, 20);
lbl7.setSize(230, 20);
lbl8.setSize(230, 20);
lbl9.setSize(230, 20);
btn1.setSize(150, 20);
btn2.setSize(150, 20);
jt1.setSize(230, 20);
jt2.setSize(230, 20);
jt3.setSize(230, 20);
jt4.setSize(230, 20);
jt5.setSize(230, 20);
jt6.setSize(230, 20);
jt7.setSize(230, 20);
jt8.setSize(230, 20);
jt9.setSize(230, 20);
tbl1.setSize(1, 1);
// pack the frame for better cross platform support
f.pack();
// Make it visible
f.setVisible(true);
f.setSize(600,500); // default size is 0,0
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // End of Gui Method
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Driver();
}
});
} // End main Method
} // End class Driver
array in the address class
public void ShippingLabel(String[]args) {
Object [][] sl = {{"555 Hello Ln", "Capital, TX 77777"}};
}
in the main class
btn1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn1MouseClicked(evt);
tbl1.setText(ShippingLabel(sl[0]));
}
});