From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3702.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java new file mode 100644 index 0000000..22dc3c6 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java @@ -0,0 +1,57 @@ +/* Listing3702.java */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; + +public class Listing3702 +extends JFrame +implements ActionListener, CaretListener +{ + public Listing3702() + { + super("JTextField"); + addWindowListener(new WindowClosingAdapter(true)); + Container cp = getContentPane(); + cp.setLayout(new FlowLayout()); + JTextField tf; + //Linksbündiges Textfeld mit "Hello, world" + tf = new JTextField("Hello, world"); + cp.add(tf); + //Leeres Textfeld mit 20 Spalten + tf = new JTextField(20); + cp.add(tf); + //Textfeld mit "Hello, world" und 20 Spalten + tf = new JTextField("Hello, world", 20); + tf.addActionListener(this); + tf.addCaretListener(this); + cp.add(tf); + } + + public void actionPerformed(ActionEvent event) + { + JTextField tf = (JTextField)event.getSource(); + System.out.println("---ActionEvent---"); + System.out.println(tf.getText()); + System.out.println(tf.getSelectedText()); + System.out.println(tf.getSelectionStart()); + System.out.println(tf.getSelectionEnd()); + System.out.println(tf.getCaretPosition()); + } + + public void caretUpdate(CaretEvent event) + { + System.out.println("---CaretEvent---"); + System.out.println(event.getDot()); + System.out.println(event.getMark()); + } + + public static void main(String[] args) + { + Listing3702 frame = new Listing3702(); + frame.setLocation(100, 100); + frame.setSize(300, 150); + frame.setVisible(true); + } +} \ No newline at end of file -- cgit v1.2.3