9. RadioButtonDemo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jradiobutton.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import java.awt.*;
import javax.swing.*;
public class jradiobutton extends JFrame
{
JRadioButton c1,c2,c3;
ButtonGroup bg;
public jradiobutton()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
bg=new ButtonGroup();
c1=new JRadioButton();
c2=new JRadioButton("B");
c3=new JRadioButton("c",true);
bg.add(c1);
bg.add(c2);
bg.add(c3);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
jradiobutton rd=new jradiobutton();
}
}
//****************************End*************************************
10. RadioButton & MenuItem Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jradiobuttonmenuitem.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jradiobuttonmenuitem extends JFrame
{
JMenuBar mb;
JMenu f,e;
JMenuItem o,s;
public jradiobuttonmenuitem()
{
mb=new JMenuBar();
f=new JMenu();
f.setMnemonic('f');
f.setText("File");
e=new JMenu("Edit");
o=new JMenuItem("Open",'o');
s=new JMenuItem("Save",'s');
f.add(o);
f.addSeparator();
f.add("OK");
e.add(s);
mb.add(f);
mb.add(e);
setJMenuBar(mb);
setSize(200,200);
setVisible(true);
}
public static void main(String[] args) {
jradiobuttonmenuitem jm=new jradiobuttonmenuitem();
}
}
//****************************End*************************************
11. ScrollPane Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jscrollpane.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*******************************Start****************************
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class jscrollpane extends JFrame
{
JTable t;
JScrollPane sp;
public jscrollpane()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
String col[]={"Rollno","Name","Class"};
String data[][]={{"1","ABC","FY"},{"2","XYZ","SY"},{"3","PQR","TY"}};
t=new JTable(data,col);
sp=new JScrollPane(t);
c.add(sp);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
jscrollpane js=new jscrollpane();
}
}
//************************************End***************************
12. Saperator Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jseperator.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*******************************Start****************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jseperator extends JFrame
{
public jseperator()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton b1=new JButton("OK");
JButton b2=new JButton("Cancel");
JSeparator sp=new JSeparator(JSeparator.VERTICAL);
sp.setPreferredSize(new Dimension(1,50));
c.add(b1);
c.add(sp);
//pack();
setSize(200,200);
setVisible(true);
}
public static void main(String[] args) throws Exception
{
new jseperator();
}
}
//*************************End***************************
13. Text Area Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jtextarea.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*******************************Start****************************
import javax.swing.*;
import java.awt.*;
public class jtextarea extends JFrame
{
JTextArea t1,t2,t3,t4;
public jtextarea()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextArea();
t2=new JTextArea("Enter here");
t3=new JTextArea(10,20);
t4=new JTextArea("java",10,10);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
jtextarea ja=new jtextarea();
}
}
//*************************End***************************
12. Saperator Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jseperator.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*******************************Start****************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jseperator extends JFrame
{
public jseperator()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton b1=new JButton("OK");
JButton b2=new JButton("Cancel");
JSeparator sp=new JSeparator(JSeparator.VERTICAL);
sp.setPreferredSize(new Dimension(1,50));
c.add(b1);
c.add(sp);
//pack();
setSize(200,200);
setVisible(true);
}
public static void main(String[] args) throws Exception
{
new jseperator();
}
}
13. Text Area Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jtextarea.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.
//*******************************Start****************************
import javax.swing.*;
import java.awt.*;
public class jtextarea extends JFrame
{
JTextArea t1,t2,t3,t4;
public jtextarea()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextArea();
t2=new JTextArea("Enter here");
t3=new JTextArea(10,20);
t4=new JTextArea("java",10,10);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
jtextarea ja=new jtextarea();
}
}
No comments:
Post a Comment
Welcome, happy learning