Hello,
The following program has a JButton and a JLabel in a JFrame. I am using Flow Layout.
How do I get the JLabel to show directly below the JButton before clicking the JButton and after clicking the JButton?
Thank you!
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class checks extends JFrame
{
private JButton button;
private JLabel label;
public checks()
{
button = new JButton("Click Here");
label = new JLabel ("I am here");
Container container = getContentPane();
container.setLayout (new FlowLayout());
container.add(button);
container.add(label);
button.addActionListener (
new ActionListener()
{
public void actionPerformed( ActionEvent e)
{
label.setText("Who are you");
}
}
);
setVisible(true);
setSize(500, 500);
}
public static void main(String args[])
{
checks m = new checks();
}
}