Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Properties;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import java.awt.Font;
- import javax.swing.JTextField;
- import javax.swing.JTextArea;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Bäckerliste extends JFrame {
- private JPanel contentPane;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Bäckerliste frame = new Bäckerliste();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Bäckerliste() {
- setTitle("B\u00E4ckerliste");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 649, 197);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JButton neueBestellungButton = new JButton("Neue Bestellung");
- neueBestellungButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- FileWriter fw = null;
- try {
- fw = new FileWriter("C:\\Users\\waldhoern\\Desktop\\Bäckerliste.txt");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- BufferedWriter bw = new BufferedWriter(fw);
- String username = new Properties(System.getProperties()).getProperty("user.name");
- boolean running = true;
- String benutzerBestellung = JOptionPane.showInputDialog("Was möchtest du bestellen, "+username+"?");
- try {
- bw.write("Bestellungen vom 19.03.2019:");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- bw.newLine();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- bw.newLine();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- do {
- try {
- bw.write(username + ": " +benutzerBestellung);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- bw.newLine();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- benutzerBestellung = JOptionPane.showInputDialog("Möchtest du sonst noch was bestellen, "+username+"?\nFalls nicht, bitte schreibt \"fertig\".");
- if (benutzerBestellung.contains("fertig")) {
- System.out.println("Bestellung ist fertig");
- running = false;
- try {
- bw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- } while (running == true);
- System.out.println("Programm geht weiter");
- }
- });
- neueBestellungButton.setFont(new Font("Tahoma", Font.BOLD, 14));
- neueBestellungButton.setBounds(10, 70, 200, 80);
- contentPane.add(neueBestellungButton);
- JButton bestellungEditierenButton = new JButton("Bestellung editieren");
- bestellungEditierenButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- FileReader fr = null;
- try {
- fr = new FileReader("C:\\Users\\waldhoern\\Desktop\\Bäckerliste.txt");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- BufferedReader br = new BufferedReader(fr);
- try {
- br.readLine();
- System.out.println();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- bestellungEditierenButton.setFont(new Font("Tahoma", Font.BOLD, 14));
- bestellungEditierenButton.setBounds(220, 70, 200, 80);
- contentPane.add(bestellungEditierenButton);
- JButton bestellungLöschenButton = new JButton("Bestellung l\u00F6schen");
- bestellungLöschenButton.setFont(new Font("Tahoma", Font.BOLD, 14));
- bestellungLöschenButton.setBounds(430, 70, 200, 80);
- contentPane.add(bestellungLöschenButton);
- JTextArea InfoTextBestellTool = new JTextArea();
- InfoTextBestellTool.setText("Ihr k\u00F6nnt hier eure Bestellungen erstellen, editieren und l\u00F6schen.");
- InfoTextBestellTool.setBounds(13, 22, 620, 22);
- contentPane.add(InfoTextBestellTool);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement