Creating Buttons in java

Hi,

I am new to java.. i have created two butons and the objective of first button is to print a string( Say "Hello world") till the next button is pressed.

so Button1 : prints "Hello World"

Button 2: Exit.

Iam facing problem in the 2 nd button, since it is not allowing me to exit.

can some body help me in solving this problem.

Thank you

anand.

[395 byte] By [meetanandan] at [2007-9-30 16:48:32]
# 1
Post some code:-)
Martin3 at 2007-7-6 13:00:44 > top of Java-index,Administration Tools,Sun Connection...
# 2
I think you are using loop behind the button 1. Whenever you run loop, it halts the program and even system until loop finishes. Your problem can be solved if you use thread. but since your are at beginner level so it can't be done.
amersohail794 at 2007-7-6 13:00:44 > top of Java-index,Administration Tools,Sun Connection...
# 3

Are you sure that you've added an action listener to both buttons? For instance

[code]

public class MyButtons extends ... implements ActionListener

...

JButton button1 = new JButton("Hello World");

button1.addActionListener(this);

button1.setActionCommand("hello world");

// add the button to your layout

JButton button2 = new JButton("Exit");

button2.addActionListener(this);

button2.setActionCommand("exit");

// add the button to your layout

...

public void actionPerformed(ActionEvent evt)

{

if(evt.getActionCommand().equals("hello world")

{

System.out.println("Hello world");

} else

{

System.exit(0);

}

}

Greyhill at 2007-7-6 13:00:44 > top of Java-index,Administration Tools,Sun Connection...