Hello, I am a beginner in java programming and I have recently had difficulty saving my data entered from my Jtextfield into mysql database.
This is my current code, it runs fine but I don't know what I need to add to save my data into mysql database.
This is my current code for my main method class:
This is my current code for my main menu class:public class Main{ public static void main(String[] args) { new MyFrame(); } }
import javax.swing.*; import java.awt.*; public class MyFrame extends JFrame{ JLabel label; JMenu Add; JMenu remove; JMenu items; JMenu vendors; JMenuBar menuBar; JMenuItem addCustomer; JMenuItem addVendors; JMenuItem addProducts; JMenuItem removeCustomer; JMenuItem removeProduct; JMenuItem removeVendor; MyFrame(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); label = new JLabel("Inventory Software"); label.setFont(new Font("Comic Sans MS", Font.BOLD, 30)); menuBar = new JMenuBar(); Add = new JMenu("Add"); remove = new JMenu("Remove"); items = new JMenu("Items"); vendors = new JMenu("Vendors"); addCustomer = new JMenuItem("Add Customers"); addVendors = new JMenuItem("Add Vendors"); addProducts = new JMenuItem("Add Products"); removeCustomer = new JMenuItem("Remove Customer"); removeProduct = new JMenuItem("Remove Product"); removeVendor = new JMenuItem("Remove Vendor"); remove.add(removeCustomer); remove.add(removeProduct); remove.add(removeVendor); Add.add(addCustomer); Add.add(addProducts); Add.add(addVendors); menuBar.add(Add); menuBar.add(remove); menuBar.add(items); menuBar.add(vendors); addCustomer.addActionListener(new WindowAC()); addVendors.addActionListener(new WindowAV()); addProducts.addActionListener(new WindowAP()); removeCustomer.addActionListener(new WindowRC()); removeVendor.addActionListener(new WindowRV()); removeProduct.addActionListener(new WindowRP()); this.setPreferredSize(new Dimension(550, 300)); this.setJMenuBar(menuBar); this.add(label); this.pack(); this.setVisible(true); this.getContentPane().setBackground(Color.WHITE); this.setLocationRelativeTo(null); this.setTitle("Intact Communications Inventory Software"); } }
This is my current code for my add customer class:
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class WindowAC implements ActionListener { public void actionPerformed(ActionEvent e) { if("Add Customers".equals(e.getActionCommand())){ JFrame windowAC = new JFrame(); JLabel label = new JLabel("Name:"); JLabel label1 = new JLabel("Address:"); JLabel label2 = new JLabel("Email:"); JLabel label3 = new JLabel("Tel: "); JLabel label4 = new JLabel("FAX: "); JLabel label5 = new JLabel(" "); JTextField textField = new JTextField(); JTextField textField1 = new JTextField(); JTextField textField2 = new JTextField(); JTextField textField3 = new JTextField(); JTextField textField4 = new JTextField(); JButton button = new JButton("Submit"); label.setBounds(50, 100, 100, 50); label1.setBounds(50, 150, 100, 50); label2.setBounds(50, 200, 100, 50); label3.setBounds(50, 250, 100, 50); label4.setBounds(50, 300, 100, 50); label5.setBounds(50, 350, 100, 50); textField.setBounds(150, 110, 400, 30); textField1.setBounds(150, 160, 400, 30); textField2.setBounds(150, 210, 400, 30); textField3.setBounds(150, 260, 400, 30); textField4.setBounds(150, 310, 400, 30); button.setBounds(300, 450, 100, 70); windowAC.setSize(750,750); windowAC.getContentPane().setBackground(Color.WHITE); windowAC.setTitle("Add Customer info"); windowAC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); windowAC.setVisible(true); windowAC.setLocationRelativeTo(null); windowAC.add(button); windowAC.add(label); windowAC.add(textField); windowAC.add(label1); windowAC.add(textField1); windowAC.add(label2); windowAC.add(textField2); windowAC.add(label3); windowAC.add(textField3); windowAC.add(label4); windowAC.add(textField4); windowAC.add(label5); } } }
I was hoping ya'll could help, been stuck on this problem for a very long time.