Showing posts with label gui component in java. Show all posts
Showing posts with label gui component in java. Show all posts

Saturday, 13 April 2019

JFrame in Java - Online Help

JFrame in Java:

The JFrame in java is a class which is used to create a user-defined window. The JFrame class defines the following constructors:

JFrame()

It is used to create empty JFrame.

JFrame(String str)

It is used to create a JFrame with the specified string.

Methods for JFrame in  Java:

Container getContentPane()

The getContentPane() method is used to return the content pane object for this JFrame.

void add(component c)

This method is used to add the given components to the content pane of this frame.

Sample program for JFrame in java:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFramedemo
{
public static void main(String arg[])
{
JFrame jf= new JFrame("online help");
Container c=jf.getContentPane();
c.setLayout(new BorderLayout());
c.add(new JButton("yes");
jf.setBounds(0,0,300,200);
jf.setVisible(true);
}
}


Monday, 8 April 2019

JList in Java | Online Help

JList in java:

The JList is used to let the user select one or more items from the list. The JList class defines the following constructors:

JList():

It is used to create an empty JList with default four rows visible.

JList(vector v)

It is used to create a JList with the specified vector object.

Methods for JList in Java:

The most commonly used JList() method is as follows:

void addItem(object obj)

This method is used to add a new object to the list.

int getSelectedIndex()

This method is used to return the index of the selected item.

int[] getSelectedItem()

This method is used to return the string value of the item selected.

Sample program for JList in Java:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jlistdemo
{
public static void main(String args[])
{
String[] str={"professor","Associate professor","Assistant professor")
JFrame jf=new JFrame("JListDemo");
JList j1=new JList(str);
jf.getContentPane().add(j1,BorderLayout.CENTER);
jf.pack();
jf.setVisible(true);
}
}