Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame Crash?  RSS feed

 
par koh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

Here we have a typical GUI application that uses mainFrame.pack method to initialize main window. The odd thing is that it runs ok but sometimes after a normal exit and again startup, the system hangs with no erro or obvious reason. We traced it and it showed up that it is stopped at this method! Any comment?
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post some code
 
par koh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi here is the siplified code. Note that now this code crashes at some other object!

package com.sanaa.kashaneh;
import com.sanaa.kashaneh.*;
import com.sanaa.utils.*;


import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.lang.*;
import java.awt.image.*;
import javax.swing.border.*;
import java.nio.channels.*;
import java.awt.*;

import java.util.ArrayList;
import javax.swing.JSplitPane;
import java.util.Locale;
import javax.swing.UIManager;
import com.nilo.plaf.nimrod.NimRODLookAndFeel;
import com.nilo.plaf.nimrod.NimRODTheme;.

.
public class Kashaneh extends JvmTermination implements ActionListener {
.
private javax.swing.JTextField status;
private ApplicationListeners appListener;
private JMenuBar menuBar;
private JToolBar toolBar;
private KashanehTabbedPane kTabbedPane;
private Rectangle rRestoreDefaultLocation;
private final String iconExtension = ".png";

.
public Kashaneh () {

setName("Kashaneh");
mySplash = new MySplashScreen();

try {
dbAccess = new DBAccess(config.home+"/database", "kashaneh");.
}
}catch (Exception e){
.
showError(e.getMessage()+"\n"+e.getCause());
}

setLookAndFeel();
appListener = new ApplicationListeners();
appListener.addActionListener(this);
initGUI();

} // End of methode Kashaneh

/**
* setLookAndFeel
*
*/
public static void setLookAndFeel (){
try {

NimRODTheme nt = new NimRODTheme();
nt.setPrimary1( new Color(99,112,187));
nt.setPrimary2( new Color(109,122,197));
nt.setPrimary3( new Color(119,132,207));
nt.setSecondary1( new Color(184,184,184));
nt.setSecondary2( new Color(194,194,194));
nt.setSecondary3( new Color(204,204,204));
nt.setWhite( new Color(255,255,255));
nt.setBlack( new Color(0,0,0));
nt.setMenuOpacity(195);
nt.setFrameOpacity(180);

NimRODLookAndFeel NimRODLF = new NimRODLookAndFeel();
NimRODLF.setCurrentTheme( nt);
UIManager.setLookAndFeel( NimRODLF);


} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}

UIManager.put("TitledBorder.titleColor",new java.awt.Color(0,70,213));
UIManager.getDefaults().put("Button.focusInputMap",
new UIDefaults.LazyInputMap(new Object[]
{"ENTER", "pressed",
"released ENTER", "released",

}));


} // End of methode setLookAndFeel

public void run()
{
while (this.jvmTermSignal() == false) {
try {
Thread.sleep(3000);
}catch(Exception ignore){
ignoreException();
}
}
this.jvmSetSignal(false);
}

private void initGUI()
{



mainFrame = new JFrame();
mainFrame.setName("MinaFrame");
mainFrame.setTitle("Kashaneh")


mainFrame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm();
}});

mainFrame.setResizable(true);
mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Toolkit toolkit = Toolkit.getDefaultToolkit();

mainFrame.setIconImage(toolkit.getImage(config.imagesPath+"/kashanehicon"+iconExtension));

addStatus();

menuBar = new JMenuBar();
menuBar.setName("MenuBar");
Border loweredetched;
loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
menuBar.setBorder(loweredetched);
menuBar.setBorderPainted(true);

JMenu fileMenu = new JMenu(bundle.getMessage("file"));
fileMenu.add(createMenuItem("backup",KeyEvent.VK_B, ActionEvent.CTRL_MASK));
fileMenu.add(createMenuItem("recovery", KeyEvent.VK_R, ActionEvent.CTRL_MASK));

JCheckBoxMenuItem cbMenuItem;
cbMenuItem = new JCheckBoxMenuItem(bundle.getMessage("autoBackup"));
fileMenu.add(cbMenuItem);
cbMenuItem.setActionCommand("autoBackup");
cbMenuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_B, ActionEvent.ALT_MASK));
cbMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
appListener.fireActionEvent(evt);
}
});
fileMenu.add(createMenuItem("export", KeyEvent.VK_E, ActionEvent.CTRL_MASK));
fileMenu.add(createMenuItem("import", KeyEvent.VK_M, ActionEvent.CTRL_MASK));
fileMenu.add(createMenuItem("exit", KeyEvent.VK_E, ActionEvent.ALT_MASK));
menuBar.add(fileMenu);

JMenu toolMenu = new JMenu(bundle.getMessage("tools"));
toolMenu.add(createMenuItem("rtl", KeyEvent.VK_R, ActionEvent.SHIFT_MASK));
toolMenu.add(createMenuItem("ltr", KeyEvent.VK_L, ActionEvent.SHIFT_MASK));
toolMenu.add(createMenuItem("restoreDefault", KeyEvent.VK_D, ActionEvent.SHIFT_MASK));
menuBar.add(toolMenu);

JMenu helpMenu = new JMenu(bundle.getMessage("help"));
helpMenu.add(createMenuItem("contents",KeyEvent.VK_H, ActionEvent.CTRL_MASK));
helpMenu.add(createMenuItem("about",KeyEvent.VK_A, ActionEvent.CTRL_MASK));
helpMenu.add(createMenuItem("www",0,0));
helpMenu.getItem(2).setEnabled(false);
helpMenu.add(createMenuItem("faq",KeyEvent.VK_F, ActionEvent.CTRL_MASK));
helpMenu.add(createMenuItem("kanoon",KeyEvent.VK_K, ActionEvent.CTRL_MASK));
helpMenu.add(createMenuItem("procedure",KeyEvent.VK_P, ActionEvent.CTRL_MASK));

menuBar.add(helpMenu);
mainFrame.setJMenuBar(menuBar);


toolBar = new JToolBar("ToolBar");
String[] jbName = {"backup","export","import","contents","faq",
"www","kanoon","rtl","ltr" ,"contents","restoreDefault"};
JButton[] jb = new JButton[jbName.length];
java.net.URL iconPath;
for (int i=0; i < jbName.length; i++) {
jb[i] = new JButton();
iconPath = getClass().getResource("images/"+jbName[i]+"24"+iconExtension);
if(iconPath != null)
jb[i].setIcon (new ImageIcon(iconPath));
jb[i].setToolTipText(bundle.getMessage(jbName[i]+"ToolTip"));

jb[i].setActionCommand(jbName[i]);
jb[i].addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
appListener.fireActionEvent(evt);
}
});
toolBar.add(jb[i]);
} // End of for
toolBar.setMaximumSize(toolBar.getSize( ));
mainFrame.getContentPane().add(toolBar, BorderLayout.NORTH);

addNavigatorAndFormPanel();

java.util.Locale farsiLocale = new java.util.Locale("fa", "IR");
farsiLocale.setDefault(farsiLocale);
mainFrame.setLocale(farsiLocale);


mainFrame.applyComponentOrientation(
ComponentOrientation.getOrientation(
mainFrame.getLocale()));

kTabbedPane.adjustOrientation();

mainFrame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent event) {
setStatus(mainFrame.getSize().toString());
}
});

mainFrame.pack();

mainFrame.setLocationRelativeTo(null);



mainFrame.setVisible(true);

rRestoreDefaultLocation = mainFrame.getBounds();



} // End of initGUI






public static void main(String args[]) //throws Exception
{

PrintStream stdout = System.out;
PrintStream stderr = System.err;
PrintStream p = null;
try {
config = new GetConf("Kashaneh");
} catch (MyException me) {
showError(me.getMessage());
}
bundle = new MessagesBundle(config.lang, config.country);

String lockDir = config.home+"\\kashaneh.lock";
try {
FileLock lck = new FileOutputStream(lockDir).getChannel().tryLock(0L,4L,false);
if(lck == null) {
MessageDialog md = new MessageDialog(config.imagesPath+"/kashanehicon.jpg",
"Kashaneh Dialog", bundle.getMessage("alreadyRunning"),
bundle.getMessage("ok"), null, null, null, 5);
md.getValue() ;
System.exit(0);
}
}catch (IOException ie) {
showError(ie.getMessage());
} catch (OverlappingFileLockException oe) {
showError(oe.getMessage());
}

try
{

FileOutputStream out = new FileOutputStream(config.home+"\\kashaneh.log");
p = new PrintStream( out );
System.setOut(p);
System.setErr(p);
}
catch (Exception e)
{
showError("Redirection error: "+e.getMessage());
}

ShutdownHook sh = new ShutdownHook();
Runtime.getRuntime().addShutdownHook(sh);
Kashaneh kashaneh = new Kashaneh();
kashaneh.start();


if( p != null ){
try {
p.close();
}catch (Exception ie){
ignoreException();
}
}
System.setOut(stdout);
System.setErr(stderr);
} // End of main method


private static GetConf config;
private static MessagesBundle bundle;
private About about = null;
private JFrame mainFrame;
private JPanel formPanel;
private DynamicTree dTreePanel;
private FormSplitPane splitPane;
private static final int LTR = 0;
private static final int RTL = 1;
private DBAccess dbAccess = null;




} // End of class Kashaneh
 
par koh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,

Did anybody notice my code??
Any idea?
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very unfortunate that nobody has commented, particualrly after asking you to post the code. Unfortunately we cannot run the code because we don't have access to the com.sanaa packages.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!