-
Bug
-
Resolution: Fixed
-
P3
-
1.1.3
-
swing1.0fcs
-
sparc
-
solaris_2.5.1
Name: diC59631 Date: 12/02/97
1. Compile the following source code, SimpleExample.java
2. run it.
3. choose Save from menu File
4. one file called test.pres saved in the current dir.
5. this time, check JButton and JTextField, they are all working fine.
6. then, choose Load from menu File
7. JButton still can be clicked, but JTextField can't accept input any more.
It looks like a serializable problem.
We are using JFC swing-0.5.1 version.
This problem is quite critical for our current development, please help us.
//----start the source code, SimpleExample.java------
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SimpleExample extends JPanel
{
//The Frame
public static Frame frame;
//The MenuBar
public static MenuBar menuBar = null;
public static SimpleExample example = null;
public SimpleExample()
{
super(true);
// Create the button
JButton button = new JButton("Simple Test");
JTextField text = new JTextField("1234567890");
add(button);
add(text);
}
MenuBar createMenuBar()
{
menuBar = new MenuBar();
//File Menu
Menu file = new Menu("File");
MenuItem saveItem = new MenuItem("Save");
saveItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
savePanel();
}
}
);
MenuItem loadItem = new MenuItem("Load");
loadItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loadPanel();
}
}
);
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
);
file.add(saveItem);
file.add(loadItem);
file.add(exitItem);
menuBar.add(file);
return menuBar;
}
public void savePanel()
{
System.out.println("SavePanel called ");
try {
FileOutputStream f = new FileOutputStream("test.pres");
ObjectOutput s = new ObjectOutputStream(f);
s.writeObject(example);
s.flush();
s.close();
} catch (IOException e) {
System.err.println("Failed to save a Panel to file ");
e.printStackTrace();
}
}
public void loadPanel()
{
SimpleExample pres = null;
System.out.println("LoadPanel called ");
try {
FileInputStream in = new FileInputStream("test.pres");
ObjectInput sin = new ObjectInputStream(in);
pres = (SimpleExample) sin.readObject();
sin.close();
} catch (FileNotFoundException e) {
System.err.println("Panel file not found.");
} catch (Exception e) {
System.err.println("Failed to load a Panel from file");
e.printStackTrace();
}
frame.remove(example);
frame.add("Center", example = pres);
}
public static void main(String[] args)
{
frame = new Frame("SimpleExample");
frame.add("Center", example = new SimpleExample());
frame.setMenuBar(example.createMenuBar());
frame.pack();
frame.setVisible(true);
}
}
//----end of SimpleExample.java------
(Review ID: 21177)
======================================================================