Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Java AWT Form

883128
Member Posts: 1
Hi everybody,
I'm developing the first Applets, I made a window extending Frame class and I used KeyListener to write on it from keyboard.
I'd like to have a method that resize the text creating a new paragraph everytime the text exceed the width of the window, such
a common Text Editor.
Do you know such a method or how I can realize one to accomplish this task?
Thanks in advance,
Paolo F.C.
P.S. here is my code :
I'm developing the first Applets, I made a window extending Frame class and I used KeyListener to write on it from keyboard.
I'd like to have a method that resize the text creating a new paragraph everytime the text exceed the width of the window, such
a common Text Editor.
Do you know such a method or how I can realize one to accomplish this task?
Thanks in advance,
Paolo F.C.
P.S. here is my code :
******************************************* package com.testapplet; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Window extends Frame { public String testo = ""; public Ascoltatore asc; public AscoltaTastiera asc_tast; public static void main(String argv[]) { Window wind = new Window(); } Window() { setBounds(0,0,800,600); setTitle(getClass().getName()); setVisible(true); setBackground(Color.white); setForeground(Color.black); asc = new Ascoltatore(); asc_tast = new AscoltaTastiera(this); addWindowListener(asc); addKeyListener(asc_tast); } public void paint(Graphics g) { testo = asc_tast.testo; g.drawString(testo, 10, 22+14); } } ******************************************* package com.testapplet; import java.awt.event.*; public class Ascoltatore extends WindowAdapter { public void windowClosed (WindowEvent evt) { System.out.println(evt); System.exit(0); } public void windowClosing (WindowEvent evt) { evt.getWindow().dispose(); System.out.println(evt); } } ********************************************* package com.testapplet; import java.awt.*; import java.awt.event.*; public class AscoltaTastiera implements KeyListener { public String testo = ""; public Frame parent; public AscoltaTastiera(Frame frame) { this.parent = frame; } public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) { testo += e.getKeyChar(); if (testo != null) parent.repaint(); } }Edited by: 880125 on 18-ago-2011 5.49
Tagged:
Answers
-
Some hints:
You might want to use Swing instead of AWT, since Swing is newer and has more and easier to use components.
The g.drawString() method will not wrap the text, that's why there are ready made components for that. I'm not sure about AWT (well, at least the TextArea), but with Swing you have components like JTextPane. -
Moderator action: Moved from Java Programming.
Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.
Then edit your post and format the code correctly.
db
This discussion has been closed.