Suppose that a table named Table.txt is stored in a text file. The first line in the file is the header, and the remaining lines correspond to rows in the table. The elements are separated by commas. Write a java program to display the table using Labels in Grid Layout.

Program Code:
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
class A extends JFrame 
{
public A() 
{
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout g = new GridLayout(0,3);
setLayout(g);
try 
{
FileInputStream fin = new FileInputStream("D:/emp.txt");
Scanner sc = new Scanner(fin).useDelimiter(",");
String[] arrayList;
String a;
while (sc.hasNextLine()) 
{
a = sc.nextLine();
arrayList = a.split(",");
for (String i : arrayList) 
{
add(new
JLabel(i));
}
}
} catch (Exception ex) 
{
}
setDefaultLookAndFeelDecorated(true);
pack();
setVisible(true);
}
}
public class Tbl 
{
public static void main(String[] args) 
{
A a = new A();
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: