Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sound;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import java.sql.*;
- import javax.swing.JLabel;
- import javax.swing.ImageIcon;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.math.BigDecimal;
- public class webshop extends JFrame {
- private JPanel contentPane;
- private JTextField tfPreis;
- private JTextField tfvorname;
- private JTextField tfnachname;
- private JTextField tfstrasse;
- private JTextField tfhausnummer;
- private JTextField tfpostleitzahl;
- private JTextField tfid;
- /*Variablendeklaration*/
- double Gitarre;
- double Gibson, Takamine, HarleyBentonSC, HarleyBenton, Ortega, Cordoba;
- double GibsonP, TakamineP, HarleyBentonSCP, HarleyBentonP, OrtegaP, CordobaP;
- /**
- * Launch the application.
- */
- public static void main (String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- webshop frame = new webshop();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- createConnection();
- createConnection2();
- }
- public static void createConnection() {
- final String hostname = "localhost";
- final String port = "3306";
- final String dbname = "gitarrenwebshopdb";
- final String user = "root";
- final String password = "root";
- Connection conn = null;
- try {
- System.out.println("* Treiber laden");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- }
- catch (Exception e) {
- System.err.println("Unable to load driver.");
- e.printStackTrace();
- }
- try {
- System.out.println("* Verbindung aufbauen");
- String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
- conn = DriverManager.getConnection(url, user, password);
- System.out.println("* Statement beginnen");
- Statement stmt = conn.createStatement();
- System.out.println("* Abfrage beginnen");
- String sqlCommand = "SELECT ID, Artikel, Preis FROM artikeltb";
- ResultSet rs = stmt.executeQuery(sqlCommand);
- System.out.println("* Ergebnisse anzeigen");
- while (rs.next()) {
- String id = rs.getString(1);
- String artikel = rs.getString("Artikel");
- double preis = rs.getDouble(3);
- System.out.println( id +" "+artikel+" "+preis );
- }
- System.out.println("* Statement beenden");
- stmt.close();
- System.out.println("* Datenbank-Verbindung beenden");
- conn.close();
- }
- catch (SQLException sqle) {
- System.out.println("SQLException: " + sqle.getMessage());
- System.out.println("SQLState: " + sqle.getSQLState());
- System.out.println("VendorError: " + sqle.getErrorCode());
- sqle.printStackTrace();
- }
- }
- public static void createConnection2() {
- final String hostname = "localhost";
- final String port = "3306";
- final String dbname = "gitarrenwebshopdb";
- final String user = "root";
- final String password = "root";
- Connection conn = null;
- try {
- System.out.println("* Treiber laden");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- }
- catch (Exception e) {
- System.err.println("Unable to load driver.");
- e.printStackTrace();
- }
- try {
- System.out.println("* Verbindung aufbauen");
- String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
- conn = DriverManager.getConnection(url, user, password);
- System.out.println("* Statement beginnen");
- Statement stmt = conn.createStatement();
- System.out.println("* Abfrage beginnen");
- String sqlCommand =
- "SELECT ID, Vorname, Nachname, Strasse, Hausnummer, Postleitzahl, Zahlungsart, Artikel FROM bestellungtb";
- ResultSet rs = stmt.executeQuery(sqlCommand);
- System.out.println("* Ergebnisse anzeigen");
- while (rs.next()) {
- String id2 = rs.getString(1);
- String Vorname = rs.getString(2);
- String Nachname = rs.getString(3);
- String Strasse = rs.getString(4);
- double Hausnummer = rs.getDouble(5);
- double Postleitzahl = rs.getDouble(6);
- String Zahlungsart = rs.getString(7);
- String Artikel2 = rs.getString(8);
- double Preis2 = rs.getDouble(9);
- System.out.println( id2 +" "+Vorname+" "+Nachname+" "+Strasse+" "+Hausnummer+" "+Postleitzahl+" "+Zahlungsart+" "+Artikel2+" "+Preis2 );
- }
- System.out.println("* Statement beenden");
- stmt.close();
- System.out.println("* Datenbank-Verbindung beenden");
- conn.close();
- }
- catch (SQLException sqle) {
- System.out.println("SQLException: " + sqle.getMessage());
- System.out.println("SQLState: " + sqle.getSQLState());
- System.out.println("VendorError: " + sqle.getErrorCode());
- sqle.printStackTrace();
- }
- return;
- }
- public int eintragen(String Vorname , String Nachname, String Strasse, String Hausnummer, String Postleitzahl, String Zahlungsart, String Artikel2, String Preis2) {
- Connection conn = null;
- try {
- conn = DriverManager.getConnection("jdbc:mysql://localhost/login?user=root&password=root");
- Statement stmt = conn.createStatement();
- return stmt.executeUpdate("INSERT INTO bestellungtb(Vorname) VALUES('"+ Vorname +"' , '"+ Nachname +"', '"+ Strasse +"' , '"+ Hausnummer +"' , '"+ Postleitzahl +"', '"+ Zahlungsart +"' , '"+ Artikel2 +"' , '"+ Preis2 +"')");
- }
- catch (SQLException e) {
- return 0;
- }
- }
- /**
- * Create the frame.
- */
- public webshop() {
- setTitle("Gitarrenwebshop");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 727, 720);
- contentPane = new JPanel();
- contentPane.setFont(new Font("Tahoma", Font.BOLD, 11));
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- /*******************************************************
- ******************* Labels ****************************
- *******************************************************/
- JLabel lblgibson = new JLabel("");
- lblgibson.setVisible(false);
- lblgibson.setIcon(new ImageIcon(webshop.class.getResource("/sound/gibson.jpg")));
- lblgibson.setBounds(10, 39, 131, 400);
- contentPane.add(lblgibson);
- JLabel lblcordoba = new JLabel("");
- lblcordoba.setVisible(false);
- lblcordoba.setIcon(new ImageIcon(webshop.class.getResource("/sound/cordoba.jpg")));
- lblcordoba.setBounds(10, 39, 158, 400);
- contentPane.add(lblcordoba);
- JLabel lblharleybentonsc = new JLabel("");
- lblharleybentonsc.setVisible(false);
- lblharleybentonsc.setIcon(new ImageIcon(webshop.class.getResource("/sound/harley_benton_sc.jpg")));
- lblharleybentonsc.setBounds(10, 39, 131, 400);
- contentPane.add(lblharleybentonsc);
- JLabel lblharleybenton = new JLabel("");
- lblharleybenton.setIcon(new ImageIcon(webshop.class.getResource("/sound/harley_benton.jpg")));
- lblharleybenton.setVisible(false);
- lblharleybenton.setBounds(10, 39, 158, 400);
- contentPane.add(lblharleybenton);
- JLabel lblortega = new JLabel("");
- lblortega.setIcon(new ImageIcon(webshop.class.getResource("/sound/ortega.jpg")));
- lblortega.setVisible(false);
- lblortega.setBounds(10, 39, 145, 400);
- contentPane.add(lblortega);
- JLabel lbltakamine = new JLabel("");
- lbltakamine.setVisible(false);
- lbltakamine.setIcon(new ImageIcon(webshop.class.getResource("/sound/takamine.jpg")));
- lbltakamine.setBounds(10, 39, 158, 400);
- contentPane.add(lbltakamine);
- JLabel lblauswahl = new JLabel("");
- lblauswahl.setIcon(new ImageIcon(webshop.class.getResource("/sound/auswahl.jpg")));
- lblauswahl.setBounds(10, 39, 152, 400);
- contentPane.add(lblauswahl);
- JLabel lblgitarrenauswahl = new JLabel("Gitarrenauswahl:");
- lblgitarrenauswahl.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblgitarrenauswahl.setBounds(10, 11, 691, 20);
- contentPane.add(lblgitarrenauswahl);
- JLabel lblInfo = new JLabel("(Jede Gitarre ist auch f\u00FCr einen Aufpreis von 50 Euro in einem Pack (Stimmger\u00E4t, Gigpack, Gurt) erh\u00E4ltlich)");
- lblInfo.setFont(new Font("Tahoma", Font.PLAIN, 11));
- lblInfo.setBounds(178, 11, 523, 20);
- contentPane.add(lblInfo);
- JLabel lblpreis = new JLabel("Preis (EUR)");
- lblpreis.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblpreis.setBounds(365, 425, 76, 14);
- contentPane.add(lblpreis);
- JLabel lblvorname = new JLabel("Vorname");
- lblvorname.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblvorname.setBounds(178, 71, 76, 14);
- contentPane.add(lblvorname);
- JLabel lblnachname = new JLabel("Nachname");
- lblnachname.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblnachname.setBounds(178, 134, 108, 14);
- contentPane.add(lblnachname);
- JLabel lblstrasse = new JLabel("Strasse");
- lblstrasse.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblstrasse.setBounds(178, 190, 46, 14);
- contentPane.add(lblstrasse);
- JLabel lblhausnummer = new JLabel("Hausnummer");
- lblhausnummer.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblhausnummer.setBounds(390, 190, 171, 14);
- contentPane.add(lblhausnummer);
- JLabel lblpostleitzahl = new JLabel("Postleitzahl");
- lblpostleitzahl.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblpostleitzahl.setBounds(178, 246, 94, 14);
- contentPane.add(lblpostleitzahl);
- JLabel lblzahlungsart = new JLabel("Zahlungsart");
- lblzahlungsart.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblzahlungsart.setBounds(178, 303, 94, 14);
- contentPane.add(lblzahlungsart);
- JLabel lblbestellungen = new JLabel("Bestellung einsehen:");
- lblbestellungen.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblbestellungen.setBounds(10, 529, 131, 14);
- contentPane.add(lblbestellungen);
- JLabel lblid = new JLabel("ID");
- lblid.setFont(new Font("Dialog", Font.BOLD, 12));
- lblid.setBounds(10, 554, 46, 14);
- contentPane.add(lblid);
- JLabel lblausgabe = new JLabel("");
- lblausgabe.setBounds(10, 492, 691, 14);
- contentPane.add(lblausgabe);
- JLabel lblpruefen = new JLabel("");
- lblpruefen.setBounds(10, 608, 691, 14);
- contentPane.add(lblpruefen);
- /*******************************************************
- ******************* Textfelder ************************
- *******************************************************/
- tfPreis = new JTextField();
- tfPreis.setEditable(false);
- tfPreis.setBounds(365, 450, 120, 20);
- contentPane.add(tfPreis);
- tfPreis.setColumns(10);
- tfvorname = new JTextField();
- tfvorname.setBounds(178, 96, 202, 20);
- contentPane.add(tfvorname);
- tfvorname.setColumns(10);
- tfnachname = new JTextField();
- tfnachname.setBounds(178, 159, 202, 20);
- contentPane.add(tfnachname);
- tfnachname.setColumns(10);
- tfstrasse = new JTextField();
- tfstrasse.setBounds(178, 215, 202, 20);
- contentPane.add(tfstrasse);
- tfstrasse.setColumns(10);
- tfhausnummer = new JTextField();
- tfhausnummer.setBounds(390, 215, 86, 20);
- contentPane.add(tfhausnummer);
- tfhausnummer.setColumns(10);
- tfid = new JTextField();
- tfid.setBounds(10, 579, 86, 20);
- contentPane.add(tfid);
- tfid.setColumns(10);
- tfpostleitzahl = new JTextField();
- tfpostleitzahl.setText("");
- tfpostleitzahl.setBounds(178, 272, 134, 20);
- contentPane.add(tfpostleitzahl);
- tfpostleitzahl.setColumns(10);
- /*******************************************************
- ******************* Buttons ***************************
- *******************************************************/
- JButton btnbestellen = new JButton("Bestellen");
- btnbestellen.setFont(new Font("Tahoma", Font.BOLD, 11));
- btnbestellen.setBounds(530, 449, 171, 23);
- contentPane.add(btnbestellen);
- JButton btnBeenden = new JButton("Beenden");
- btnBeenden.setFont(new Font("Tahoma", Font.BOLD, 11));
- btnBeenden.setBounds(530, 647, 171, 23);
- contentPane.add(btnBeenden);
- JButton btnpruefen = new JButton("Pruefen");
- btnpruefen.setFont(new Font("Tahoma", Font.BOLD, 11));
- btnpruefen.setBounds(530, 578, 171, 23);
- contentPane.add(btnpruefen);
- /*******************************************************
- ******************* ComboBox **************************
- *******************************************************/
- JComboBox cbzahlungsart = new JComboBox();
- cbzahlungsart.setModel(new DefaultComboBoxModel(new String[] {"--Bitte waehlen--", "Paypal", "Lastschrift", "Visa", "Nachname (+10 Euro)"}));
- cbzahlungsart.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- cbzahlungsart.setBounds(178, 328, 202, 20);
- contentPane.add(cbzahlungsart);
- JComboBox cbgitarre = new JComboBox();
- cbgitarre.setModel(new DefaultComboBoxModel(new String[] {"--Bitte waehlen--", "Gibson Les Paul Tribute 2018 FHB", "Gibson Les Paul Tribute 2018 FHB (Pack)", "Harley Benton SC-1000 VB Progressive Line", "Harley Benton SC-1000 VB Progressive Line (Pack)", "Ortega R121-1/4 NT", "Ortega R121-1/4 NT (Pack)", "Cordoba C9 Parlor", "Cordoba C9 Parlor (Pack)", "Harley Benton D-120CE BK", "Harley Benton D-120CE BK (Pack)", "Takamine EF341SC", "Takamine EF341SC (Pack)"}));
- cbgitarre.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- /*Es wird in den folgenden If-Abfragen geschaut, was in der ComboBox cbgitarre ausgewählt ist und danach der Variablen Gitarre
- * ein Wert zugeordnet. Zusätzlich wird das passende Bild ausgegeben und die nicht passenden wieder unsichtbar gemacht.*/
- if(cbgitarre.getSelectedItem().equals("--Bitte waehlen--")) {
- Gitarre = 0;
- lblauswahl.setVisible(true);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Gibson Les Paul Tribute 2018 FHB")) {
- Gitarre = 1;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(true);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Gibson Les Paul Tribute 2018 FHB (Pack)")) {
- Gitarre = 2;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(true);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Harley Benton SC-1000 VB Progressive Line")) {
- Gitarre = 3;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(true);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Harley Benton SC-1000 VB Progressive Line (Pack)")) {
- Gitarre = 4;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(true);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Ortega R121-1/4 NT")) {
- Gitarre = 5;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(true);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Ortega R121-1/4 NT (Pack)")) {
- Gitarre = 6;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(true);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Cordoba C9 Parlor")) {
- Gitarre = 7;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(true);
- }
- if(cbgitarre.getSelectedItem().equals("Cordoba C9 Parlor (Pack)")) {
- Gitarre = 8;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(true);
- }
- if(cbgitarre.getSelectedItem().equals("Harley Benton D-120CE BK")) {
- Gitarre = 9;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(true);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Harley Benton D-120CE BK (Pack)")) {
- Gitarre = 10;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(false);
- lblharleybenton.setVisible(true);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Takamine EF341SC")) {
- Gitarre = 11;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(true);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- if(cbgitarre.getSelectedItem().equals("Takamine EF341SC (Pack)")) {
- Gitarre = 12;
- lblauswahl.setVisible(false);
- lblgibson.setVisible(false);
- lbltakamine.setVisible(true);
- lblharleybenton.setVisible(false);
- lblharleybentonsc.setVisible(false);
- lblortega.setVisible(false);
- lblcordoba.setVisible(false);
- }
- }
- });
- cbgitarre.setBounds(10, 450, 323, 20);
- contentPane.add(cbgitarre);
- /*******************************************************
- ******************* btnBeenden ************************
- *******************************************************/
- btnBeenden.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- btnbestellen.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement