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 :
*******************************************
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