My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Paid Surveys
|
PROGRAM FOR CREATION OF TABLE IN JAVA
Posted Date: 28 Apr 2008 Resource Type: Entertainment Category: Others
|
Posted By: shirish Member Level: Bronze Rating: Points: 5
|
|
|
|
/* CREATION OF TABLE */
import java.awt.*; import java.io.*; import javax.swing.*; import javax.swing.JOptionPane.*; import java.awt.event.*; import java.awt.event.ItemEvent.*; import java.lang.*;
class Obj implements Serializable { int nof,pri; String nf[]; int typef[]; String name; Object data[][]; boolean flag=false; }
class Create extends JFrame implements ActionListener { Container c; JButton create,show,save,exit; JTable tab; Obj info=new Obj(); FileOutputStream fos; JScrollPane js;
public Create() { super("Create Table"); c=getContentPane(); c.setLayout(new FlowLayout()); setSize(500,500);
/* Create all the buttons and add actionliteners */ create=new JButton("CREATE"); c.add(create); create.addActionListener(this); show=new JButton("SHOW"); c.add(show); show.addActionListener(this); save=new JButton("SAVE"); c.add(save); save.addActionListener(this); exit=new JButton("EXIT"); c.add(exit); exit.addActionListener(this); show.setVisible(false); save.setVisible(false); exit.setVisible(false); }
public void actionPerformed(ActionEvent e) { if(e.getSource()==create) { /* Get information about table */ info.name=JOptionPane.showInputDialog(null,"Enter name of table"); info.nof=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter number of fields in table")); info.nf=new String[info.nof]; info.typef=new int[info.nof]; int cnt=0; while(cnt { info.nf[cnt]=JOptionPane.showInputDialog(null,"Enter name of fileld"); info.typef[cnt]=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter type of field \n 1.Integer\n 2.String")); if(info.flag==false) { int res=Integer.parseInt(JOptionPane.showInputDialog(null,"Is it a primary key \n 1.Yes \n 2.No ")); if(res==1) { info.pri=cnt; info.flag=true; } } cnt++; } create.setVisible(false); show.setVisible(true); } else if(e.getSource()==show) { info.data=new Object[30][info.nof]; tab=new JTable(info.data,info.nf); int v1=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h1=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; js=new JScrollPane(tab,v1,h1); js.setBounds(20,400,150,150); show.setVisible(false); save.setVisible(true); exit.setVisible(true); c.add(js); } else if(e.getSource()==save) { try { fos=new FileOutputStream(info.name+".txt"); ObjectOutputStream oos=new ObjectOutputStream(fos); oos.writeObject(info); JOptionPane.showMessageDialog(null,"Table "+info.name+" is saved"); oos.close(); fos.close(); } catch(Exception e1) { System.out.println(e1); } } else if(e.getSource()==exit) { System.exit(0); } } public static void main(String[] arge) { Create a=new Create(); a.setSize(500,600); a.show(); } }
|
Responses
|
| Author: Shyni 31 May 2008 | Member Level: Gold Points : 2 | Very useful information. Thanks.
|
|
|