Two JInternalFrames inside a JDesktopPane
I had developed 2 menu items under a menu
MENU is DISPLAY
MENUITEM-1 is DISPLAY_TABLE
MENUITEM-2 is DISPLAY_SUMMARY
When I click DISPLAY_TABLE; table is read from a file
and parsed and displayed in JTable perfectly.
But when I click DISPLAY_SUMMARY, I am not getting anything.
I feel that I had added everything correctly.
I dont know what is the mistake here in this code.
Anyone please help me. My code is here.
package javapackage;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.util.*;
import java.io.*;
publicclass DisplayTableSummaryextends JFrame
{
DefaultTableModel dtm;
JTable tbl;
JScrollPane s, scp;
int k=0;
String a,b,c,d,e;
StringTokenizer st;
//File filename1, filename2;
JTextArea txa;
JDesktopPane dsk1 =new JDesktopPane();;
Container c1=getContentPane();
File filenam;
public DisplayTableSummary()
{
JFileChooser filechooser =new JFileChooser ();
filechooser.setFileSelectionMode ( JFileChooser.FILES_ONLY);
int result = filechooser.showOpenDialog (null);
if (result== JFileChooser.CANCEL_OPTION)
{
return;
}
filenam = filechooser.getSelectedFile();
}
publicvoid displayTable()
{
if (filenam==null||filenam.getName().equals (" "))
{
JOptionPane.showMessageDialog( null,"Invalid File Name","Invalid FileName", JOptionPane.ERROR_MESSAGE );
}
else
{
tableGUI();
dynamicTable();
//repaint();
}
}
publicvoid displaySummary()
{
if (filenam==null||filenam.getName().equals (" "))
{
JOptionPane.showMessageDialog( null,"Invalid File Name","Invalid FileName", JOptionPane.ERROR_MESSAGE );
}
else
{
textAreaGUI();
textfmFile();
}
}
publicvoid tableGUI()
{
// Container c=getContentPane();
dtm =new DefaultTableModel();
//dtm.setRowCount(m);
dtm.addColumn("PAYMENT NUMBER");
dtm.addColumn ("PAYMENT AMOUNT");
dtm.addColumn ("PRINCIPLE");
dtm.addColumn ("INTEREST");
dtm.addColumn("LOAN BALANCE");
tbl =new JTable(dtm);
s =new JScrollPane(tbl);
//dsk1 = new JDesktopPane();
c1.add(dsk1);
JInternalFrame inf1 =new JInternalFrame("Internal Frame",true,true,true,true);
inf1.setSize(350,350);
Container con1=inf1.getContentPane();
con1.add(s);
inf1.setOpaque(false);
dsk1.add(inf1);
inf1.setVisible(true);
setSize(400,400);
setVisible(true);
}
publicvoid dynamicTable()
{
System.out.println("I am ready to display your table");
try
{
FileInputStream file =new FileInputStream(filenam);
InputStreamReader i =new InputStreamReader(file);
BufferedReader in =new BufferedReader(i);
String s="PAYMENT NUMBERPAYMENTPRINCIPLEINTERESTBALANCE";
String line =" ",noline=" ";
do
{
line=in.readLine();
System.out.println(line);
}while(!line.equals(s));
noline=in.readLine();
while((line=in.readLine()) !=null)
{
k++;
noline=in.readLine();
st=new StringTokenizer(line);
a=st.nextToken();
b=st.nextToken();
c=st.nextToken();
d=st.nextToken();
e=st.nextToken();
Vector rows=new Vector();
rows.add(a);
rows.add(b);
rows.add(c);
rows.add(d);
rows.add(e);
dtm.addRow(rows);
}
}
catch ( IOException e )
{
e.printStackTrace();
JOptionPane.showMessageDialog (null,"File Does not exist","Invalid File Name", JOptionPane.ERROR_MESSAGE);
}
}
publicvoid textAreaGUI()
{
c1.add(dsk1);
txa =new JTextArea();
scp.add(txa);
JInternalFrame inf2 =new JInternalFrame("Internal Frame",true,true,true,true);
inf2.setSize(350,350);
Container con2=inf2.getContentPane();
con2.add(scp);
inf2.setOpaque(false);
dsk1.add(inf2);
inf2.setVisible(true);
setSize(400,400);
setVisible(true);
}
publicvoid textfmFile()
{
System.out.println("I am ready to display your summary");
try
{
FileInputStream file =new FileInputStream(filenam);
InputStreamReader i =new InputStreamReader(file);
BufferedReader in =new BufferedReader(i);
String line=" ";
String s="PAYMENT NUMBERPAYMENTPRINCIPLEINTERESTBALANCE";
line=in.readLine();
do
{
line += in.readLine()+"/n";
System.out.println(line);
}while(!line.equals(s));
txa.setText(line);
}
catch ( IOException e )
{
e.printStackTrace();
JOptionPane.showMessageDialog (null,"File Does not exist","Invalid File Name", JOptionPane.ERROR_MESSAGE);
}
}
}
=======================================================
JMenu service =new JMenu("Services");
JMenuItem s1=new JMenuItem ("Display Amortization");
JMenuItem s2=new JMenuItem ("Display Summary");
service.add(s1);
service.add(s2);
s1.addActionListener(handler);
s2.addActionListener(handler);
class TextFieldHandlerimplements ActionListener
{
publicvoid actionPerformed (ActionEvent event)
{
if (event.getSource()== s1)
{
DisplayTableSummary a1=new DisplayTableSummary();
a1.displayTable();
}
elseif (event.getSource()== s2)
{
DisplayTableSummary a2=new DisplayTableSummary();
a2.displaySummary();
}
}
}

