0

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();
        }
        
    }
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by sciprog1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.