SWING / NOTES</>↗Swing12 Nov 2010
The insert(String str, int pos) of the JTextArea allows us to insert a text at the specified position. In the example below we insert brown and over words into the current JTextArea text. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class TextAreaInsertText extends JPanel { public TextAreaInsertText() { initializeUI(); } public static void showFrame() { […]
SWING / NOTES</>↗Swing12 Nov 2010
In this example you’ll see how to use the replaceRange(String str, int start, int end) method to replace a string in the JTextArea from the start position to the end position with the specified string. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class TextAreaReplaceText extends JPanel { public TextAreaReplaceText() { initializeUI(); } public static void […]
CORE API / NOTES</>↗Core API07 Nov 2010
If you want a thread to work until another thread dies, you can join the thread onto the end of the another thread using the join() method. For example, you want thread B only work until thread A completes its work, then you want thread B to join thread A. package org.kodejava.example.lang; public class ThreadJoin […]
CORE API / NOTES</>↗Core API07 Nov 2010
Threads always run with some priority, usually represented as a number between 1 and 10 (although in some cases the range is less than 10). A thread gets a default priority that is the priority of the thread of execution that creates it. But, you can also set a thread’s priority directly by calling the […]
CORE API / NOTES</>↗Core API07 Nov 2010
To get the currently executing thread, use the static currentThread() method of the Thread class. This method returns a reference of the currently executing thread object. package org.kodejava.lang; public class GetCurrentThreadDemo { public static void main(String[] args) { // Get the currently executing thread object Thread thread = Thread.currentThread(); System.out.println("Id : " + thread.getId()); System.out.println("Name […]
CORE API / NOTES</>↗Core API07 Nov 2010
You can assign a name to thread instance by using the setName() method and get the name of the thread using the getName() method. The naming support is also available as a constructor of the Thread class such as Thread(String name) and Thread(Runnable target, String name). package org.kodejava.lang; public class ThreadNameDemo extends Thread { public […]