Algorithm-VSM
view release on metacpan or search on metacpan
examples/corpus/EventThreadDemo2.java view on Meta::CPAN
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
});
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.getDocument().addDocumentListener(
new MyDocumentListener());
MyTools.printThreadInfo( //(I)
"Just after registering document listener:" );
JScrollPane areaScrollPane = new JScrollPane(textArea);
MyTools.printThreadInfo( //(J)
"Just after creating the scroll pane:" );
areaScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
areaScrollPane.setPreferredSize(new Dimension(250, 250));
areaScrollPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Plain Text"),
BorderFactory.createEmptyBorder(5,5,5,5)),
areaScrollPane.getBorder()));
frame.getContentPane().add(
areaScrollPane, BorderLayout.CENTER );
MyTools.printThreadInfo( "Just before calling pack:" );
frame.pack();
frame.setLocation( 300, 300 );
frame.setVisible( true );
MyTools.printThreadInfo("Just after calling setVisible:");//(K)
}
}
/////////////////////////// class MyTools ///////////////////////////
class MyTools { //(L)
public static void printThreadInfo( String s ) { //(M)
System.out.println( s );
// Thread.currentThread().getThreadGroup().list();
// System.out.println(
// "Number of threads in the current thread group: "
// + Thread.currentThread().getThreadGroup().activeCount() );
System.out.println( "The current thread is: "
+ Thread.currentThread() );
}
public static void keepBusy( int howLong ) { //(N)
long curr = System.currentTimeMillis();
while ( System.currentTimeMillis() < curr + howLong )
;
}
}
////////////////////// class MyDocumentListener /////////////////////
class MyDocumentListener implements DocumentListener {
public void insertUpdate( final DocumentEvent e ) {
String str = null;
Document doc = e.getDocument();
int lengthText = doc.getLength();
try {
str = doc.getText( lengthText - 1, 1 );
} catch( BadLocationException badloc ) {
badloc.printStackTrace();
}
MyTools.printThreadInfo("From iniside the listener:");//(O)
MyTools.keepBusy( 500 );
System.out.print( str );
}
public void removeUpdate(DocumentEvent e) { }
public void changedUpdate(DocumentEvent e) { }
}
( run in 0.681 second using v1.01-cache-2.11-cpan-39bf76dae61 )