import java.awt.*;
02 import javax.swing.*;
03 import java.util.Random;
04 import java.awt.event.*;
05 import java.awt.Color;
06 import java.awt.Graphics;
07 public class actualstuff extends JFrame
08 {
09 private JTextField textField1;
10 public static int index=0;
11 public static Graphics gx;
12 public actualstuff()
13 {
14 Container container=getContentPane();
15 container.setLayout(new FlowLayout());
16 textField1=new JTextField(15);
17 container.add(textField1);
18 setSize(325, 100);
19 setVisible(true);
20 TextFieldHandler handler=new TextFieldHandler();
21 textField1.addActionListener(handler);
22 }
23 public static void main(String args[])
24 {
25 actualstuff application=new actualstuff();
26 application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27 }
28 private class TextFieldHandler implements ActionListener
29 {
30 public void actionPerformed(ActionEvent event)
31 {
32 String string="";
33 if (event.getSource()==textField1)
34 {
35 index=1;
36 }
37 }
38 }
I want to make a text field and monitor it for when enter is pressed. when I change public static void main to public void init, it works properly, but it does not work with main, and i want this not to be an applet.
eventually, i will add a loop that runs until index is changed to 1 (starts at 0), and index is changed when enter is hit from the text field. Where should that that loop be placed?