|
| 1 | +import javax.swing.*; |
| 2 | +import java.awt.*; |
| 3 | +import java.awt.event.*; |
| 4 | +class MyApp extends JFrame |
| 5 | +{ |
| 6 | + |
| 7 | + /** |
| 8 | + * File 4/4 of jdbc series |
| 9 | + * Call this class to input data from CL to sql table |
| 10 | + */ |
| 11 | + |
| 12 | +MyApp() |
| 13 | +{ |
| 14 | + Container c=getContentPane(); |
| 15 | + c.setLayout(null); |
| 16 | + |
| 17 | + JLabel title = new JLabel("Insert values to table"); |
| 18 | + JLabel l1 = new JLabel("product name"); |
| 19 | + JTextField t1 =new JTextField(20); |
| 20 | + JLabel l2 = new JLabel("product price"); |
| 21 | + JTextField t2 =new JTextField(20); |
| 22 | + JButton Jb=new JButton("Add to table"); |
| 23 | + title.setBounds(200,50,150,30); |
| 24 | + c.add(title); |
| 25 | + l1.setBounds(100,100,200,20); |
| 26 | + c.add(l1); |
| 27 | + l2.setBounds(100,200,200,20); |
| 28 | + c.add(l2); |
| 29 | + t1.setBounds(300,100,200,20); |
| 30 | + c.add(t1); |
| 31 | + t2.setBounds(300,200,200,20); |
| 32 | + c.add(t2); |
| 33 | + Jb.setBounds(200,300,150,30); |
| 34 | + c.add(Jb); |
| 35 | + |
| 36 | + /** |
| 37 | + * Method defining click button event |
| 38 | + */ |
| 39 | + |
| 40 | + Jb.addActionListener(new ActionListener() |
| 41 | + { |
| 42 | + public void actionPerformed(ActionEvent e) |
| 43 | + { |
| 44 | + |
| 45 | + String a = t1.getText(); |
| 46 | + int b = Integer.parseInt(t2.getText()); |
| 47 | + |
| 48 | + System.out.println("hello"); |
| 49 | + System.out.println(a); |
| 50 | + System.out.println(b); |
| 51 | + |
| 52 | + JdbcHelper jh = new JdbcHelper(); |
| 53 | + |
| 54 | + jh.getStatement(); |
| 55 | + jh.insert(a,b); |
| 56 | + |
| 57 | + t1.setText(null); |
| 58 | + t2.setText(null); |
| 59 | + } |
| 60 | +}); |
| 61 | + setSize(600,600); |
| 62 | + setVisible(true); |
| 63 | + |
| 64 | +} |
| 65 | +public static void main(String[]args) |
| 66 | +{ |
| 67 | + MyApp app=new MyApp(); |
| 68 | + |
| 69 | + JdbcHelper jh = new JdbcHelper(); |
| 70 | + |
| 71 | + jh.getStatement(); |
| 72 | + |
| 73 | + //jh.insert("chips",40); |
| 74 | +} |
| 75 | +} |
0 commit comments