Here's the basic frame for a console-based Java application:
class yourApp { public static void main (String args[]) { // Or 'String[] args' System.out.println("A line of text outputted to stdout"); } }
Constant | What it represents |
---|---|
Event.HOME | The Home key |
Event.END | The End key |
Event.PGUP, PGDN | The Page Up and Page Down keys |
Event.UP, DOWN, LEFT, RIGHT | The Up, Down, Left, and Right arrow keys(i.e. Event.LEFT) |
F1..12 | The keys F1 through F12(i.e. Event.F5) |
import java.awt.*; import java.applet.Applet; public class yourApplet extends java.applet.Applet { TextField inputField; // Our input box Button bt1; // The OK button String st=""; // Holds the inputted text public void init () { // The parameter is how many characters wide it is TextField inputField=new TextField(15); Button bt1=new Button("&OK"); // Or whatever caption you want add(inputField); add(bt1); // Add the controls /* Set the layout to a flow layout(I don't really know if this is necessary */ setLayout(new FlowLayout()); } // The action() method is called for any event public void action (Event e, Object what) { if (e.target==bt1) { // Our OK button received an event // Call upon the powers of OOP to get the text of our input field st=inputField.getText(); } } }
class yourApp extends Thread { public static void main (String args[]) { // Make a new thread object from our class Thread thread1=new Thread(new yourApp()); // Start the thread thread1.start(); } public void run () { // Some code here } }