john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

swing form example no listener

import java.awt.*;
import javax.swing.*;

public class JavaGui extends JFrame
{
    private static final long serialVersionUID = 1L;

    JButton button1 = new JButton("Button1");
    JLabel label1 = new JLabel("Label1",JLabel.LEFT);
    JTextField text1 = new JTextField();
    JRadioButton radio1 = new JRadioButton("Yes" , true );

    JavaGui()
    {
        Container c = getContentPane();
        c.setLayout( null );
        //c.setLayout( new GridLayout(2,3)) or c.setLayout( new FlowLayout() )

        c.add( button1 );
        c.add( label1 );
        c.add( text1 );
        c.add( radio1 );

        button1.setBounds( 10 , 30 , 120 , 40 );
        label1.setBounds( 10 , 60 , 80 , 40 );
        text1.setBounds( 50 , 90 , 80 , 40 );
        radio1.setBounds( 50 , 120 , 80 , 40 );

        setSize( 250 , 250 );
        setTitle("Java GUI Example");
        setVisible( true );
        setResizable( false );
    } // end GuiRun()


    public static void main(String[] args)
    {
        JavaGui x = new JavaGui();      //constructor based, but needs WindowListener to close!
    }

} //end class

  • « html table example
  • jsp javabeans intro »

Published

Jul 4, 2011

Category

java

~103 words

Tags

  • example 36
  • form 20
  • java 252
  • listener 3
  • no 6
  • swing 9