0% found this document useful (0 votes)
28 views4 pages

AJP Exp 8 OP

Uploaded by

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

AJP Exp 8 OP

Uploaded by

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

X.

Practical Code:
1. Develop a program to demonstrate the use of JTable

import javax.swing.*;
import java.awt.*;
public class ProductTableExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Product Table Example");
String[] columnNames = {
"Product Name",
"Price",
"Quantity"
};
String[][] data = {
{
"Laptop",
"$1200",
"10"
},
{
"Smartphone",
"$800",
"25"
},
{
"Tablet",
"$450",
"15"
}
};
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane);
frame.setSize(400, 150);
frame.setVisible(true);
}
}
2. Write a program code to generate the following output( Refer Manual pg. no. 43)

import java.awt.*;
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();
}
}
XIII Exercise
1 Write a Java program to create a table of Name of Student, Percentage and Grade of 10
Students using JTable

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JLabel;
class Exercise_1 extends JFrame {
Exercise_1() {
String[][] data = {
{"1", "Smith Tikadiya", "96", "A+"},
{"2", "Shresth Singh", "92", "A+"},
{"3", "Ram Panjwani", "90", "A+"},
{"4", "Aniket Nikam", "88", "A"},
{"5", "Soham Ramjiyani", "89", "A"},
{"6","Kkrishna Bhanushali","84","A"},
{"7", "Varun Dawda", "86", "A"},
{"8", "Pushkar Shinde", "82", "A"},
{"9", "Soham Ghadge", "79", "B+"},
{"10", "Ishak Ansari", "75", "B+"}
};
String[] col = {"Id", "Name", "Percentage", "Grade"};
JTable table = new JTable(data, col);
JScrollPane sp = new JScrollPane(table);
add(sp);
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Exercise_1();
}
}

You might also like