Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.util.Properties;
  9.  
  10. import javax.swing.JFrame;
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JPanel;
  13. import javax.swing.border.EmptyBorder;
  14. import javax.swing.JButton;
  15. import java.awt.Font;
  16. import javax.swing.JTextField;
  17. import javax.swing.JTextArea;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.ActionEvent;
  20.  
  21. public class Bäckerliste extends JFrame {
  22.  
  23.     private JPanel contentPane;
  24.  
  25.     /**
  26.      * Launch the application.
  27.      */
  28.     public static void main(String[] args) {
  29.         EventQueue.invokeLater(new Runnable() {
  30.             public void run() {
  31.                 try {
  32.                     Bäckerliste frame = new Bäckerliste();
  33.                     frame.setVisible(true);
  34.                 } catch (Exception e) {
  35.                     e.printStackTrace();
  36.                 }
  37.             }
  38.         });
  39.     }
  40.  
  41.     /**
  42.      * Create the frame.
  43.      */
  44.     public Bäckerliste() {
  45.         setTitle("B\u00E4ckerliste");
  46.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.         setBounds(100, 100, 649, 197);
  48.         contentPane = new JPanel();
  49.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  50.         setContentPane(contentPane);
  51.         contentPane.setLayout(null);
  52.        
  53.         JButton neueBestellungButton = new JButton("Neue Bestellung");
  54.         neueBestellungButton.addActionListener(new ActionListener() {
  55.             public void actionPerformed(ActionEvent arg0) {
  56.                 FileWriter fw = null;
  57.                 try {
  58.                     fw = new FileWriter("C:\\Users\\waldhoern\\Desktop\\Bäckerliste.txt");
  59.                 } catch (IOException e) {
  60.                     // TODO Auto-generated catch block
  61.                     e.printStackTrace();
  62.                 }
  63.                 BufferedWriter bw = new BufferedWriter(fw);
  64.                
  65.                 String username = new Properties(System.getProperties()).getProperty("user.name");
  66.                
  67.                 boolean running = true;
  68.                
  69.                 String benutzerBestellung = JOptionPane.showInputDialog("Was möchtest du bestellen, "+username+"?");
  70.                
  71.                 try {
  72.                     bw.write("Bestellungen vom 19.03.2019:");
  73.                 } catch (IOException e) {
  74.                     // TODO Auto-generated catch block
  75.                     e.printStackTrace();
  76.                 }
  77.                 try {
  78.                     bw.newLine();
  79.                 } catch (IOException e) {
  80.                     // TODO Auto-generated catch block
  81.                     e.printStackTrace();
  82.                 }
  83.                 try {
  84.                     bw.newLine();
  85.                 } catch (IOException e) {
  86.                     // TODO Auto-generated catch block
  87.                     e.printStackTrace();
  88.                 }
  89.                
  90.                 do {
  91.                
  92.                 try {
  93.                     bw.write(username + ":      " +benutzerBestellung);
  94.                 } catch (IOException e) {
  95.                     // TODO Auto-generated catch block
  96.                     e.printStackTrace();
  97.                 }
  98.                 try {
  99.                     bw.newLine();
  100.                 } catch (IOException e) {
  101.                     // TODO Auto-generated catch block
  102.                     e.printStackTrace();
  103.                 }
  104.                
  105.                 benutzerBestellung = JOptionPane.showInputDialog("Möchtest du sonst noch was bestellen, "+username+"?\nFalls nicht, bitte schreibt \"fertig\".");
  106.                
  107.                 if (benutzerBestellung.contains("fertig")) {
  108.                     System.out.println("Bestellung ist fertig");
  109.                     running = false;
  110.                     try {
  111.                         bw.close();
  112.                     } catch (IOException e) {
  113.                         // TODO Auto-generated catch block
  114.                         e.printStackTrace();
  115.                     }
  116.                 }
  117.            
  118.                 } while (running == true);
  119.                
  120.                 System.out.println("Programm geht weiter");
  121.                
  122.             }
  123.         });
  124.         neueBestellungButton.setFont(new Font("Tahoma", Font.BOLD, 14));
  125.         neueBestellungButton.setBounds(10, 70, 200, 80);
  126.         contentPane.add(neueBestellungButton);
  127.        
  128.         JButton bestellungEditierenButton = new JButton("Bestellung editieren");
  129.         bestellungEditierenButton.addActionListener(new ActionListener() {
  130.             public void actionPerformed(ActionEvent arg0) {
  131.                 FileReader fr = null;
  132.                
  133.                 try {
  134.                     fr = new FileReader("C:\\Users\\waldhoern\\Desktop\\Bäckerliste.txt");
  135.                 } catch (IOException e) {
  136.                     // TODO Auto-generated catch block
  137.                     e.printStackTrace();
  138.                 }
  139.                 BufferedReader br = new BufferedReader(fr);
  140.                
  141.                 try {
  142.                     br.readLine();
  143.                     System.out.println();
  144.                 } catch (IOException e) {
  145.                     // TODO Auto-generated catch block
  146.                     e.printStackTrace();
  147.                 }
  148.              
  149.                
  150.                
  151.                
  152.                
  153.                
  154.                
  155.                
  156.                
  157.                
  158.                
  159.             }
  160.         });
  161.         bestellungEditierenButton.setFont(new Font("Tahoma", Font.BOLD, 14));
  162.         bestellungEditierenButton.setBounds(220, 70, 200, 80);
  163.         contentPane.add(bestellungEditierenButton);
  164.        
  165.         JButton bestellungLöschenButton = new JButton("Bestellung l\u00F6schen");
  166.         bestellungLöschenButton.setFont(new Font("Tahoma", Font.BOLD, 14));
  167.         bestellungLöschenButton.setBounds(430, 70, 200, 80);
  168.         contentPane.add(bestellungLöschenButton);
  169.        
  170.         JTextArea InfoTextBestellTool = new JTextArea();
  171.         InfoTextBestellTool.setText("Ihr k\u00F6nnt hier eure Bestellungen erstellen, editieren und l\u00F6schen.");
  172.         InfoTextBestellTool.setBounds(13, 22, 620, 22);
  173.         contentPane.add(InfoTextBestellTool);
  174.        
  175.        
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement