------------------------------------------------------------------------------------------- Main Methode: public class MainMethod { public static void main(String[] args) { DataInputGui dataInputGui = new DataInputGui(); } } ------------------------------------------------------------------------------------------- Store Program (wobei in dieser Version nur ein Feld unterstützt wird): import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Transaction; import net.sf.hibernate.cfg.Configuration; /* * Created on Dec 13, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author denis * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class StoreData { String store(String [] s) { try { // Create the SessionFactory Configuration cfg = new Configuration().addClass(User1.class); SessionFactory factory = cfg.buildSessionFactory(); // Create the Session Session session = factory.openSession(); // Create the Transaction Transaction tx = session.beginTransaction(); //Create new User and store them the database User1 newUser1 = new User1(); //newUser1.setID("dr"); newUser1.setUserName(s[0]); session.save(newUser1); tx.commit(); // close our session and release resources session.flush(); session.close(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); } String returnString = "store successfully completed"; return (returnString); } } Gui Program: import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class DataInputGui implements ActionListener { String returnMsg; JTextField textField1 = new JTextField(20); JTextField textField2 = new JTextField(20); JTextField textField3 = new JTextField(20); JTextField textField4 = new JTextField(20); JTextField returnField = new JTextField(40); public DataInputGui() { JLabel label1 = new JLabel("Label-1"); JLabel label2 = new JLabel("Label-2"); JLabel label3 = new JLabel("Label-3"); JLabel label4 = new JLabel("Label-4"); //Create and set up the window. JFrame frame = new JFrame("generisches gui"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFrame.setDefaultLookAndFeelDecorated(true); JPanel panel = new JPanel(); frame.getContentPane().add(panel); panel.setLayout(new GridLayout(6,2)); JButton saveDataButton = new JButton("save data now"); saveDataButton.addActionListener(this); panel.add(saveDataButton); JLabel label = new JLabel(" inputfields :"); panel.add(label); panel.add(label1); panel.add(textField1); panel.add(label2); panel.add(textField2); panel.add(label3); panel.add(textField3); panel.add(label4); panel.add(textField4); JLabel returnStatus = new JLabel("return status: "); panel.add (returnStatus); panel.add (returnField); //Display the window. frame.pack(); frame.setSize(500,200); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { System.out.println("textField1 :" + textField1.getText()); System.out.println("textField2 :" + textField2.getText()); System.out.println("textField3 :" + textField3.getText()); System.out.println("textField4 :" + textField4.getText()); String [] array = {textField1.getText(), textField2.getText(), textField3.getText(), textField4.getText()}; StoreData storeData = new StoreData(); returnMsg = storeData.store(array); returnField.setText(returnMsg); textField1.setText(""); textField2.setText(""); textField3.setText(""); textField4.setText(""); } } --------------------------------------------------------------------------------------------- OtherDenisRaschpichler - 14 Dec 2004
Topic GenerischeDb-Eingabemaske . { |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors.
|
This website has been archived and is no longer maintained.