Friday, 2 May 2014

Example of Choice in Java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="Ex63.java" width=500 height=400></applet>*/
public class Ex63 extends Applet
{
  MyChoice choice;
  public void init()
  {
    choice=new MyChoice();
    choice.add("Red");
    choice.add("Green");
    choice.add("Blue");
    add(choice);
  }
  class MyChoice extends Choice
  {
    public MyChoice()
     {
       enableEvents(AWTEvent.ITEM_EVENT_MASK);
     }
    protected void processItemEvent(ItemEvent ie)
    {
         showStatus("Choice selection:"+getSelectedItem());
         super.processItemEvent(ie);
    }
  }

Example Of Jtable

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

/*<applet code="JTabledemo" width=400 height=200></applet>*/

public class JTabledemo extends JApplet
{


public void init()
{
Container c=getContentPane();



c.setLayout(new BorderLayout());

String[] colHeads={"name","phone no","city"};

Object[][] data={
{"abc","9999999","pune"},
{"xyz","8888888","mumbai"}
};

JTable tb=new JTable(data,colHeads);




int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(tb,v,h);

c.add(jsp,BorderLayout.CENTER);



}


}




Example Of Java Program For JScrollbar (Implement ScrollBar)

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

/*<applet code="JScrolldemo" width=200 height=200></applet>*/

public class JScrolldemo extends JApplet
{
public void init()
{

Container c=getContentPane();

c.setLayout(new BorderLayout());

JPanel jp=new JPanel();
jp.setLayout(new GridLayout(2,2));


JRadioButton b1=new JRadioButton("Indian Express");
jp.add(b1);
JRadioButton b2=new JRadioButton("Times of India");
jp.add(b2);
JRadioButton b3=new JRadioButton("Sakal");
jp.add(b3);
JRadioButton b4=new JRadioButton("Lokmat");
jp.add(b4);

ButtonGroup bg1=new ButtonGroup();
ButtonGroup bg2=new ButtonGroup();
bg1.add(b1);
bg1.add(b2);
bg2.add(b3);
bg2.add(b4);

int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(jp,v,h);

c.add(jsp,BorderLayout.CENTER);


}

}