Advertisement
Cihat47

Cihat47

Jun 28th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.28 KB | None | 0 0
  1. package getATR;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.WindowAdapter;
  6. import java.awt.event.WindowEvent;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import javax.smartcardio.CardException;
  10. import javax.swing.*;
  11.  
  12. import javax.swing.text.AttributeSet;
  13. import javax.swing.text.BadLocationException;
  14. import javax.swing.text.PlainDocument;
  15.  
  16. import java.sql.Connection;
  17. import java.sql.DriverManager;
  18. import java.sql.SQLException;
  19.  
  20. public class GUI_ATR extends JFrame{
  21.    
  22.     // Meine Button
  23.     public static JButton daten_pruefen = new JButton("<html>Daten<br>pruefen</html>");
  24.     public static JButton pruefung_abschließen = new JButton("<html>Pruefung<br>abschliessen</html>");
  25.    
  26.     public static JLabel lblKartennr = new JLabel("* Karten-Nr.:");
  27.     public static JFormattedTextField txtFKartennr = new JFormattedTextField();
  28.    
  29.     // das hier ist neu:
  30.     public static String blabla = null;
  31.    
  32.     public static String b = "346";
  33.     public static String c = "456";
  34.  
  35.     public Connection con;
  36.    
  37.     public static JTextArea textArea = new JTextArea();
  38.     private final JScrollPane scrollPane = new JScrollPane();
  39.    
  40.     static File f;
  41.     static String path_f;
  42.     static int returnVal;
  43.    
  44.    
  45.     public GUI_ATR(){
  46.        
  47.         setTitle("TEST");
  48.        
  49.         this.setVisible(true);
  50.         setSize(1010, 532);
  51.         setLocation(150, 100);
  52.         setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  53.         JPanel panel = new JPanel();
  54.         getContentPane().add(panel);
  55.         panel.setLayout(null);
  56.        
  57.         // Daten prüfen Button
  58.        
  59.         panel.add(daten_pruefen);
  60.         daten_pruefen.setSize(70, 35);
  61.         daten_pruefen.setLocation(5, 5);
  62.    
  63.         // Prüfung abschließen Button
  64.        
  65.         panel.add(pruefung_abschließen);
  66.         pruefung_abschließen.setSize(95, 35);
  67.         pruefung_abschließen.setLocation(350, 5);
  68.  
  69.         // Karten-Nr.:
  70.         lblKartennr.setBounds(458, 259, 81, 14);
  71.         panel.add(lblKartennr);
  72.         lblKartennr.setVisible(false);
  73.        
  74.         txtFKartennr.setBounds(579, 256, 100, 20);
  75.         panel.add(txtFKartennr);
  76.         txtFKartennr.setDocument(new FixedSizeDocument(6));
  77.         txtFKartennr.setVisible(false);
  78.        
  79.         // Text Area
  80.        
  81.         scrollPane.setBounds(5, 45, 440, 455);
  82.         panel.add(scrollPane);
  83.         scrollPane.setViewportView(textArea);
  84.        
  85.         addWindowListener(new meinWindowListener());
  86.  
  87.        
  88.     /////////////////////////////////////////////////
  89.     // Daten prüfen Button
  90.     /////////////////////////////////////////////////
  91.    
  92.    
  93.     daten_pruefen.addActionListener(new ActionListener(){
  94.     public void actionPerformed(ActionEvent e) {
  95.         open_terminal();
  96.         karteninhalt_auslesen.init_log_command_list();
  97.             gui_leeren();
  98.             open_terminal();
  99.             if (Connect_Terminal.isTerminal_present() == true) {
  100.                 open_card();
  101.                 if (Connect_Card.isCard_present() == true) {
  102.                    
  103.                     lblKartennr.setVisible(true);
  104.                     txtFKartennr.setVisible(true);
  105.                     String inhalt = txtFKartennr.getText();
  106.                     System.out.println(inhalt);
  107.                     init_osVersion();
  108.                     try {
  109.                        
  110.                         //Karteninhalt ausgeben
  111.                         karteninhalt_auslesen.ausgabe_auswahl();
  112.                    
  113.                     } catch (CardException e1) {
  114.                         e1.printStackTrace();
  115.                     }
  116.                    
  117.                 } else {
  118.                     GUI_ATR.textArea.append("Keine Karte vorhanden");
  119.                    
  120.                 }
  121.             } else {
  122.                 GUI_ATR.textArea.append("Chipkartenleser ist nicht eingesteckt");
  123.             }
  124.         }
  125.     });
  126.        
  127.         /////////////////////////////////////////////////
  128.         // Prüfung abschließen Button
  129.         /////////////////////////////////////////////////
  130.        
  131.         pruefung_abschließen.addActionListener(new ActionListener(){
  132.         public void actionPerformed(ActionEvent e) {
  133.             open_terminal();
  134.  
  135.             blabla = txtFKartennr.getText();
  136.             System.out.println("Hier der Inhalt: " +blabla );
  137.             gui_leeren();
  138.            
  139.             GUI_ATR.textArea.append("...Formular geleert!");
  140.            
  141. //------------------- ab hier Datenbanverbindung herstellen ------------------//
  142.            
  143.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  144.            
  145.             Connection con = DriverManager
  146.                     .getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)}"
  147.                                 + ";DBQ=C:/Dokumente und Einstellungen/dsv/Desktop/"
  148.                                 + "Datenbank_Test.mdb");
  149.            
  150.             try {
  151.                 con.createStatement().executeUpdate("INSERT INTO Tabelle1 (ATC,Chipkartennummer,Kurz_BLZ) VALUES ('" + blabla + "','" + b + "','" + c + "') ");
  152.                        } catch (SQLException sqle) {
  153.                             sqle.printStackTrace();
  154.                        }
  155.                   con.close();
  156.             }
  157.         });
  158.     }
  159.    
  160.     public void gui_leeren(){
  161.        
  162.         // um mein Textfeld zu leeren
  163.         textArea.setText("");
  164.         lblKartennr.setVisible(false);                 
  165.         txtFKartennr.setVisible(false);
  166.         txtFKartennr.setText("");
  167.     }
  168.    
  169.     public static void init_osVersion() {
  170.         Inhalt_ATR.init_ATR();
  171.         Inhalt_ATR.convert_atr();
  172.         Inhalt_ATR.init_all_Maps();
  173.         Inhalt_ATR.set_all_Variables();
  174.     }
  175.    
  176.  
  177.     public static void open_terminal() {
  178.         Connect_Terminal.create_factory();
  179.         try {
  180.             Connect_Terminal.create_terminals(0);
  181.         } catch (CardException e2) {
  182.             textArea.append(e2.toString());
  183.         } catch (Exception e2) {
  184.             textArea.append(e2.toString());
  185.         }
  186.     }
  187.  
  188.     public static void open_card() {
  189.         try {
  190.             Connect_Card.newCard();
  191.         } catch (CardException e1) {
  192.             GUI_ATR.textArea.append(e1.toString());
  193.         }
  194.     }
  195.  
  196.     public static void File_chooser() throws IOException {
  197.         JFileChooser fc = new JFileChooser();
  198.         fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  199.         returnVal = fc.showOpenDialog(null);
  200.  
  201.         if (returnVal == JFileChooser.APPROVE_OPTION) {
  202.             setF(fc.getSelectedFile());
  203.             setPath_f(f.getPath());
  204.         }
  205.     }
  206.  
  207.     public static File getF() {
  208.         return f;
  209.     }
  210.  
  211.     public static void setF(File f) {
  212.         GUI_ATR.f = f;
  213.     }
  214.  
  215.     public static String getPath_f() {
  216.         return path_f;
  217.     }
  218.  
  219.     public static void setPath_f(String path_f) {
  220.         GUI_ATR.path_f = path_f;
  221.     }
  222.  
  223.  
  224.     public class meinWindowListener extends WindowAdapter {
  225.         public void windowClosing(WindowEvent a) {
  226.             System.exit(0);
  227.         }
  228.     }
  229. }
  230.  
  231. //--------Fehlermeldungen-----------//
  232.  
  233. /* Exception in thread "main" java.lang.Error: Unresolved compilation problems:
  234.     Connection cannot be resolved to a type
  235.     DriverManager cannot be resolved
  236.     blabla cannot be resolved to a variable
  237.     b cannot be resolved to a variable
  238.     c cannot be resolved to a variable
  239.     SQLException cannot be resolved to a type
  240.  
  241.     at getATR.MainKlasse.main(MainKlasse.java:18) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement