|
| 1 | +package Fach_3_Swing.ch.ibw.swing.events; |
| 2 | + |
| 3 | +import javax.swing.*; |
| 4 | +import java.awt.*; |
| 5 | +import java.awt.event.ActionEvent; |
| 6 | +import java.awt.event.ActionListener; |
| 7 | + |
| 8 | +/** |
| 9 | + * Created by user on 22.01.2017. |
| 10 | + */ |
| 11 | +public class RetoEventView extends JFrame { |
| 12 | + |
| 13 | + public static final String OKBUTTON = "okPressed"; |
| 14 | + public static final String CANCELBUTTON = "cancelPressed"; |
| 15 | + |
| 16 | + // neuer Controller instanzieren, wir geben ihm als Parameter uns selber (view) mit |
| 17 | + // damit kann der Controller dann Daten direkt zu uns zurueckgeben |
| 18 | + private RetoEventController cntl = new RetoEventController(this); |
| 19 | + |
| 20 | + JLabel anzeige; |
| 21 | + public void aktualisiereAnzeige(String anzeigeText) { |
| 22 | + this.anzeige.setText(anzeigeText); |
| 23 | + } |
| 24 | + |
| 25 | + //Constructor |
| 26 | + RetoEventView() { |
| 27 | + // 2 Rows, 1 Spalte |
| 28 | + this.setLayout(new GridLayout(2,1)); |
| 29 | + |
| 30 | + JButton okButton = new JButton("ok"); |
| 31 | + // ACTIONLISTENER! |
| 32 | + okButton.addActionListener(cntl); |
| 33 | + okButton.setActionCommand(OKBUTTON); |
| 34 | + |
| 35 | + JButton cancelButton = new JButton("cancel"); |
| 36 | + // ACTIONLISTENER! |
| 37 | + cancelButton.addActionListener(cntl); |
| 38 | + cancelButton.setActionCommand(CANCELBUTTON); |
| 39 | + |
| 40 | + anzeige = new JLabel(); |
| 41 | + anzeige.setText("-"); |
| 42 | + |
| 43 | + // aufs Layout |
| 44 | + this.add(okButton); |
| 45 | + this.add(cancelButton); |
| 46 | + this.add(anzeige); |
| 47 | + } |
| 48 | + |
| 49 | +// //-------------------------------------------------------------------- |
| 50 | +// //als innere klasse |
| 51 | +// private class RetoEventController implements ActionListener { |
| 52 | +// |
| 53 | +// @Override |
| 54 | +// public void actionPerformed(ActionEvent actionEvent) { |
| 55 | +// System.out.println("command: " +actionEvent.getActionCommand()); |
| 56 | +// if (actionEvent.getActionCommand() == RetoEvent.OKBUTTON ) { |
| 57 | +// |
| 58 | +// } |
| 59 | +// } |
| 60 | +// //-------------------------------------------------------------------- |
| 61 | +// //als anonyme klasse (als Parameter in okButton.addActionListener() ) |
| 62 | +// new ActionListener() { |
| 63 | +// @Override |
| 64 | +// public void actionPerformed(ActionEvent actionEvent) { |
| 65 | +// } |
| 66 | +// }; |
| 67 | + |
| 68 | +} |
0 commit comments