Hi,
I am learning Java and I have decided that I should create my first project. I have the application code for a Tax calculator and I would like to add a GUI to it but I am struggling to work out how to enable the text field box to accept user input in the form of an integer variable. I think I may need an ActionEventListener class but don't really know how to write the code for that yet. In other words, the GUI will display a text field box where a user can enter their annual income then press enter. Then the program will calculate the tax payable and return a result.
Here is the code I have so far for the GUI, the application code is seperate:
import java.awt.*;
import java.applet.Applet.*;
public class TestLayout1 extends Frame{
public static void main(String[] args) {
// create the variables to hold input
int Income;
TestLayout1 t = new TestLayout1();
} public TestLayout1() {
// create a frame(a box to put things in)
setTitle("Taxation Calculator");
setBounds(200,200,500,500);
setLayout(new GridBagLayout());
setVisible(true);
setSize(400,400);
//set layout for panel p1
setLayout (new FlowLayout ());
Label l1 = new Label ("Enter employee's income: ");
TextField t1 = new TextField (12);
// couldn't vertically align text fields, used spaces instead
Label l2 = new Label ("Enter employee's age: ");
TextField t2 = new TextField (12);
add(l1);
add(t1);
add(l2);
add(t2);
show();
t1.setText("");
String str1 = t1.getText();
System.out.print(str1);
}}