import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ListExample
extends JFrame
{
JPanel topPanel;
JList listbox;
public ListExample()
{
// Set the frame characteristics
setTitle( "Simple ListBox Application" );
setSize( 300, 100 );
setBackground( Color.gray );
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create some items to add to the list
String listData[] =
{
"Item 1",
"Item 2",
"Item 3",
"Item 4"
};
// Create a new listbox control
listbox = new JList( listData );
topPanel.add( listbox, BorderLayout.CENTER );
}
// Main entry point for this example
public static void main( String args[] )
{
// Create an instance of the test application
ListExample mainFrame = new ListExample();
mainFrame.setVisible( true );
}
}
OUTPUT:
import java.awt.event.*;
import javax.swing.*;
class ListExample
extends JFrame
{
JPanel topPanel;
JList listbox;
public ListExample()
{
// Set the frame characteristics
setTitle( "Simple ListBox Application" );
setSize( 300, 100 );
setBackground( Color.gray );
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create some items to add to the list
String listData[] =
{
"Item 1",
"Item 2",
"Item 3",
"Item 4"
};
// Create a new listbox control
listbox = new JList( listData );
topPanel.add( listbox, BorderLayout.CENTER );
}
// Main entry point for this example
public static void main( String args[] )
{
// Create an instance of the test application
ListExample mainFrame = new ListExample();
mainFrame.setVisible( true );
}
}
OUTPUT:
1 comment:
thank u dear java has alot of scope don't worry...
you should buy a book of java which will guide u better then online courses...
if you are really intrested in online course then u should follow this link...
http://www.javatutorialhub.com/java-swing-gui.html
so if u have any problem about java programs u can ask from me..☺
Post a Comment