In linux whenever i run my gui java programe it does not show Image

My Code Is As Follows

look at line 77.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class bank implements  ActionListener
{
JFrame mainframe;
JMenuBar mbar;
JMenu file,view,help,edit;
JMenuItem newacc,exit,login,helpcontent,cust_detail,emp_detail,delEmp,delCust,addEmp;

public bank()
{
mainframe=new JFrame("Bank Application");
try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) 
    {
      System.out.println("Error setting native LAF: " + e);
    }
mbar=new JMenuBar();
mainframe.setJMenuBar(mbar); 

file=new JMenu("New");
view=new JMenu("View");
help=new JMenu("Help");
edit=new JMenu("Edit");

mbar.add(file);
mbar.add(edit);
mbar.add(view);
mbar.add(help);


newacc=new JMenuItem("New Account");
exit=new JMenuItem("Exit");
login=new JMenuItem("Log In");
cust_detail=new JMenuItem("Customer Detail");
emp_detail=new JMenuItem("Employee Detail");
helpcontent=new JMenuItem("Help Content");
delEmp=new JMenuItem("Delete Employee");
delCust=new JMenuItem("Delete Customer");
addEmp=new JMenuItem("Add Employee");

file.add(newacc);
file.add(exit);
view.add(login);
view.add(cust_detail);
view.add(emp_detail);
help.add(helpcontent);
edit.add(delEmp);
edit.add(delCust);
edit.add(addEmp);
        
newacc.addActionListener(this);
exit.addActionListener(this);
login.addActionListener(this);
helpcontent.addActionListener(this);
emp_detail.addActionListener(this);
cust_detail.addActionListener(this);
delEmp.addActionListener(this);
delCust.addActionListener(this);
addEmp.addActionListener(this);


mainframe.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
closeWarning();
}
}
);
JPanel panel=new JPanel();
panel.setBackground(Color.PINK);
JLabel label=new JLabel("Welcome To Bank Application");
JLabel label1=new JLabel(new ImageIcon("bank.jpg"));
panel.add(label);
panel.add(label1);
mainframe.add(panel);
mainframe.setVisible(true);
mainframe.setResizable(false);
mainframe.setSize(500,500);
mainframe.setLocationRelativeTo(null);
}
public static void main(String args[])
{
new bank();
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==newacc)
{
newaccount na=new newaccount();
}
else
if(e.getSource()==exit)
{
closeWarning();
}
else
if(e.getSource()==login)
{
login log=new login();
}
else
if(e.getSource()==cust_detail)
{
    tables t=new tables();
    t.custTable();
}
else
if(e.getSource()==emp_detail)
{
    tables t=new tables();
    t.empTable();
}
else
if(e.getSource()==helpcontent)
{
JOptionPane.showMessageDialog(null,"Please Register before singing in","Help",JOptionPane.INFORMATION_MESSAGE);
}
else
if(e.getSource()==addEmp)
{
    AddEmployee ae=new AddEmployee();
    ae.addEmployee();
}
else
if(e.getSource()==delCust)
{
  deleteRecord dc=new deleteRecord();
  dc.deleteCustomer();
}
else
if(e.getSource()==delEmp)
{
  deleteRecord de=new deleteRecord();
  de.deleteEmployee();
}
}
public void closeWarning()
{
int reply=JOptionPane.showConfirmDialog(null,"Are You Sure.You want To Exit From Bank Application","Bank -Exit",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(reply==JOptionPane.YES_OPTION)
{
    System.exit(0);
}
else
{
mainframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
}

Recommended Answers

All 4 Replies

what does it do? does it throw an exception, is there an error message, or does it just not show the image?

Thankx for reply
It does not throw any exception only it does not display image.

Thankx for reply
It does not throw any exception only it does not display image.

Normall you would do this to make sure the image is loaded:

ImageIcon ii=new ImageIcon("bank.jpg");
         ...
        if(ii==null){
        System.out.println("Image not loaded/found");
         //now atleast you'll know if its a problem with the location of the image or not
        } else {
            //set the image to the label
        }

Ok Thankx....

I Will try It.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.