How to know if TextArea (awt) is being typed?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1083 Views - Last Post: 01 June 2012 - 09:29 AM Rate Topic: -----

#1 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

How to know if TextArea (awt) is being typed?

Posted 30 May 2012 - 02:59 PM

well, my question above has explained what i want to know,
i'm using awt to create textarea, it's textarea, not JTextArea (swing).

thanks for help
Is This A Good Question/Topic? 0
  • +

Replies To: How to know if TextArea (awt) is being typed?

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 30 May 2012 - 03:54 PM

Add a KeyListener to it

Quote

i'm using awt to create textarea


Why, as a matter of interest?
Was This Post Helpful? 0
  • +
  • -

#3 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 02:39 AM

View Postg00se, on 30 May 2012 - 10:54 PM, said:

Add a KeyListener to it

Why, as a matter of interest?


and how to do that, i have searched in google and i can not find , most of i found were JTextArea (Swing) not TextArea (Awt)
i have a piece of code below, i want to create a text editor with a title. If user click on textarea and typing something, the title will be added a symbol "*" before default title, so the title will be look like this " *untitled "

how to add keylistener??
thanks

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;

public class MyTextarea extends JFrame implements ActionListener{

    private TextArea textarea = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
    
    public MyTextarea(){
        //contructor
        setSize(500, 400);
        setTitle("Free TextEditor v.0.1");
        setDefaultCloseOperation(EXIT_ON_CLOSE);//kalo pakai JFrame
        add(textarea);
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        //
    }
    
    public static void main(String args[]){
        MyTextarea notepad = new MyTextarea();
        notepad.setVisible(true);
    }
    
}



Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 02:47 AM

You shouldn't mix AWT and Swing visual components, so, since you're using JFrame, you should use JTextArea, in which case, you can use a DocumentListener

This post has been edited by g00se: 31 May 2012 - 02:48 AM
Reason for edit:: punctuation

Was This Post Helpful? 0
  • +
  • -

#5 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 02:51 AM

but it works,
what do you thing?
why we should not mix awt and swing???
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 02:58 AM

Quote

why we should not mix awt and swing???


It used to be because the way awt components related to their windowing peers in the OS conflicted with the way Swing components did so. That's not nearly so much of a problem now, but mixing them still muddies the design. One or the other should be used. The question is, why would you want to mix them anyway?
Was This Post Helpful? 0
  • +
  • -

#7 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 03:17 AM

Quote

why would you want to mix them anyway?


i don't know if mixing them will make some problem like that,
i'm interesting tutorial about how to create a java notepad write by gabehabe here http://www.dreaminco...on/page__st__30

he mixed awt and swing,,,
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 03:22 AM

Quote

he mixed awt and swing,,,


He did. My comments still apply. And if you run that code on an old enough vm, it's quite possible you'll get windowing problems

This post has been edited by g00se: 31 May 2012 - 03:23 AM

Was This Post Helpful? 0
  • +
  • -

#9 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 03:44 AM

Quote

And if you run that code on an old enough vm, it's quite possible you'll get windowing problems

and what about the current VM version?? any problem exist with this version??

hi, and how to add keylistener? i have searched, i have read documentation, but i can not figure out,
Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 03:55 AM

Quote

and what about the current VM version?? any problem exist with this version??


Probably unlikely to get problems. Why not just use a tutorial that doesn't mix AWT and Swing?
http://docs.oracle.c...eylistener.html
Was This Post Helpful? 0
  • +
  • -

#11 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 04:14 AM

Quote

Why not just use a tutorial that doesn't mix AWT and Swing?

i don't know but, i think mixing awt and swing is a unique, so, i'm trying this.
and also, i have not found a tutorial how to create a notepad using SWING only.

Oracle docs, i will try read it,
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to know if TextArea (awt) is being typed?

Posted 31 May 2012 - 02:19 PM

[quote name='OKIEWARDOYO' date='31 May 2012 - 07:14 AM' timestamp='1338462898' post='1634714']

Quote

i have not found a tutorial how to create a notepad using SWING only.

So put a JTextArea in it I doubt there are much differences if any...
Kind of useless in 2012 to learn how a TextArea works
Was This Post Helpful? 0
  • +
  • -

#13 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 01 June 2012 - 03:48 AM

Quote

Kind of useless in 2012 to learn how a TextArea works

and what does it mean??
will TextArea be deprecated??

Hi, btw i have done with keylistener (^^,)
Was This Post Helpful? 0
  • +
  • -

#14 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: How to know if TextArea (awt) is being typed?

Posted 01 June 2012 - 05:15 AM

Quote

and what does it mean??


It means that using AWT gui components is the old way of doing things. Unless you have a very good reason, you should use Swing
Was This Post Helpful? 0
  • +
  • -

#15 OKIEWARDOYO  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 03-April 12

Re: How to know if TextArea (awt) is being typed?

Posted 01 June 2012 - 09:06 AM

View Postg00se, on 01 June 2012 - 12:15 PM, said:

It means that using AWT gui components is the old way of doing things. Unless you have a very good reason, you should use Swing


Hem, may be i should begin thinking about this,
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2