summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing3702.java57
1 files changed, 57 insertions, 0 deletions
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