The layout manager has been added.
FlowLayout()
will position the two buttons nicely
within the area of the frame.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TwoButtons extends JFrame implements ActionListener
{
JButton redButton ;
JButton grnButton ;
// constructor for TwoButtons
public TwoButtons()
{
redButton = new JButton("Red");
grnButton = new JButton("Green");
// choose the layout manager
getContentPane().setLayout( new FlowLayout() );
getContentPane().add( redButton );
getContentPane().add( grnButton );
}
. . . . more code will go here . . . .
public static void main ( String[] args )
{
TwoButtons demo = new TwoButtons() ;
. . . . more code will go here . . . .
demo.setSize( 200, 150 );
demo.setVisible( true );
}
}
. . . . more code will go here . . . .