KEMBAR78
Java Advance | PDF | Chess | Chess Theory
0% found this document useful (0 votes)
6 views8 pages

Java Advance

Java

Uploaded by

Timepass
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Java Advance

Java

Uploaded by

Timepass
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical 2

1. import java.awt.*;

2.

3. public class ListExample1

4. {

5. // class constructor

6. ListExample1() {

7. // creating the frame

8. Frame f = new Frame();

9. // creating the list of 5 rows

10. List l1 = new List(5);

11.

12. // setting the position of list component

13. l1.setBounds(100, 100, 75, 75);

14.

15. // adding list items into the list

16. l1.add("Item 1");

17. l1.add("Item 2");

18. l1.add("Item 3");

19. l1.add("Item 4");

20. l1.add("Item 5");

21.

22. // adding the list to frame

23. f.add(l1);

24.

25. // setting size, layout and visibility of frame

26. f.setSize(400, 400);

27. f.setLayout(null);

28. f.setVisible(true);
29. }

30.

31. // main method

32. public static void main(String args[])

33. {

34. new ListExample1();

35. }

36. }

Practical 3

Import java.awt.*;

Import javax.swing.*;

Public class MyGridLayout{

JFrame f;

MyGridLayout(){

F=new JFrame();

JButton b1=new JButton(“1”);

JButton b2=new JButton(“2”);

JButton b3=new JButton(“3”);

JButton b4=new JButton(“4”);

JButton b5=new JButton(“5”);

JButton b6=new JButton(“6”);

JButton b7=new JButton(“7”);

JButton b8=new JButton(“8”);

JButton b9=new JButton(“9”);

// adding buttons to the frame

f.add(b1); f.add(b2); f.add(b3);

f.add(b4); f.add(b5); f.add(b6);


f.add(b7); f.add(b8); f.add(b9);

// setting grid layout of 3 rows and 3 columns

f.setLayout(new GridLayout(3,3));

f.setSize(300,300);

f.setVisible(true);

Public static void main(String[] args) {

New MyGridLayout();

Practical 4:

Import java.awt.*;

Import java.awt.event.*;

Import javax.swing.*;

Public class CardLayoutExample2 extends JFrame implements ActionListener{

CardLayout card;

JButton b1,b2,b3;

Container c;

CardLayoutExample2(){

C=getContentPane();

Card=new CardLayout(40,30);

//create CardLayout object with 40 hor space and 30 ver space

c.setLayout(card);
b1=new JButton(“Apple”);

b2=new JButton(“Boy”);

b3=new JButton(“Cat”);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

c.add(“a”,b1);c.add(“b”,b2);c.add(“c”,b3);

Public void actionPerformed(ActionEvent e) {

Card.next©;

Public static void main(String[] args) {

CardLayoutExample2 cl=new CardLayoutExample2();

cl.setSize(400,400);

cl.setVisible(true);

cl.setDefaultCloseOperation(EXIT_ON_CLOSE);

Practical 5:

Import javax.swing.*;

Class MenuExample

JMenu menu, submenu;

JMenuItem i1, i2, i3, i4, i5;


MenuExample(){

JFrame f= new JFrame(“Menu and MenuItem Example”);

JMenuBar mb=new JMenuBar();

Menu=new JMenu(“Menu”);

Submenu=new JMenu(“Sub Menu”);

I1=new JMenuItem(“Item 1”);

I2=new JMenuItem(“Item 2”);

I3=new JMenuItem(“Item 3”);

I4=new JMenuItem(“Item 4”);

I5=new JMenuItem(“Item 5”);

Menu.add(i1); menu.add(i2); menu.add(i3);

Submenu.add(i4); submenu.add(i5);

Menu.add(submenu);

Mb.add(menu);

f.setJMenuBar(mb);

f.setSize(400,400);

f.setLayout(null);

f.setVisible(true);

Public static void main(String args[])

New MenuExample();

}}

Practical 6:

Import javax.swing.*;

Public class ComboBoxExample {

JFrame f;

ComboBoxExample(){

F=new JFrame(“ComboBox Example”);


String country[]={“India”,”Aus”,”U.S.A”,”England”,”Newzealand”};

JComboBox cb=new JComboBox(country);

Cb.setBounds(50, 50,90,20);

f.add(cb);

f.setLayout(null);

f.setSize(400,500);

f.setVisible(true);

Public static void main(String[] args) {

New ComboBoxExample();

Practical 7 :

1. import javax.swing.*;

2. import javax.swing.tree.DefaultMutableTreeNode;

3. public class TreeExample {

4. JFrame f;

5. TreeExample(){

6. f=new JFrame();

7. DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style");

8. DefaultMutableTreeNode color=new DefaultMutableTreeNode("color");

9. DefaultMutableTreeNode font=new DefaultMutableTreeNode("font");

10. style.add(color);

11. style.add(font);

12. DefaultMutableTreeNode red=new DefaultMutableTreeNode("red");

13. DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");

14. DefaultMutableTreeNode black=new DefaultMutableTreeNode("black");

15. DefaultMutableTreeNode green=new DefaultMutableTreeNode("green");

16. color.add(red); color.add(blue); color.add(black); color.add(green);


17. JTree jt=new JTree(style);

18. f.add(jt);

19. f.setSize(200,200);

20. f.setVisible(true);

21. }

22. public static void main(String[] args) {

23. new TreeExample();

24. }}

Practical 8:

Import javax.swing.*;

Public class TableExample {

JFrame f;

TableExample(){

F=new JFrame();

String data[][]={ {“101”,”Amit”,”670000”},

{“102”,”Jai”,”780000”},

{“101”,”Sachin”,”700000”}};

String column[]={“ID”,”NAME”,”SALARY”};

JTable jt=new JTable(data,column);

Jt.setBounds(30,40,200,300);

JScrollPane sp=new JScrollPane(jt);

f.add(sp);

f.setSize(300,400);

f.setVisible(true);

Public static void main(String[] args) {

New TableExample();
}

You might also like