Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 06-02-2004, 11:10 AM   #1
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Having a problem making an image appear in a java applet

Here's the code. Basically, it's a login/splashscreen window for the program I'm writing. The only problem is that I can't get the splash screen picture to appear.

Code:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class main_interface extends JFrame{
    
    public main_interface(){
        
        //confirmation window
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new confirmationwindow());
        
        //login entry
        JLabel userL = new JLabel("User Name:", SwingConstants.RIGHT);
        JLabel passL = new JLabel("Password:", SwingConstants.RIGHT);        
        TextField userTF = new TextField(10);
        TextField passTF = new TextField(10);
        JButton loginB = new JButton("Login");
                
        //splash screen
        JLabel splashL = new JLabel();
        ImageIcon splashscreen = new ImageIcon("logo.jpg");
        splashL.setIcon(splashscreen);
                
        //userTF panel
        JPanel userTFP = new JPanel();
        userTFP.setLayout(new FlowLayout());
        userTFP.add(userTF);
        
        //passTF panel
        JPanel passTFP = new JPanel();
        passTFP.setLayout(new FlowLayout());
        passTFP.add(passTF);
        
        //login button panel
        JPanel loginBP = new JPanel();
        loginBP.setLayout(new FlowLayout());
        loginBP.add(loginB);
        
        //main panel
        JPanel mainP = new JPanel();
        mainP.setLayout(new GridLayout(1,5));
        mainP.add(userL);
        mainP.add(userTFP);
        mainP.add(passL);
        mainP.add(passTFP);
        mainP.add(loginBP);
                
        //border for login panel
        Border loginborder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "User Login" );
        mainP.setBorder(loginborder);
        
        //main container
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());
        pane.add(splashL, BorderLayout.CENTER);
        pane.add(mainP, BorderLayout.SOUTH);                
        
    }
    
    
    //confirmation window call
    private class confirmationwindow extends WindowAdapter {        
        public void windowClosing(WindowEvent e) {            
            
            int r = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Records Retention Database", JOptionPane.YES_NO_OPTION);
            if (r == JOptionPane.YES_OPTION)
                System.exit(0);
                //dispose();
       }
    }
    
        
    
    public static void main(String [] args) {
        main_interface login = new main_interface();
        login.setTitle("Records Retention Database Login");
        login.setVisible(true);
        login.setSize(600, 400);
    }
    
}
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Force Flow is offline   Reply With Quote
Old 06-02-2004, 01:57 PM   #2
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
I also tried this, but createImageIcon isn't being found for some reason. Does it need a specified package imported?

Code:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class main_interface extends JFrame{
    
    public main_interface(){
        
        //confirmation window
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new confirmationwindow());
        
        //login entry
        JLabel userL = new JLabel("User Name:", SwingConstants.RIGHT);
        JLabel passL = new JLabel("Password:", SwingConstants.RIGHT);        
        TextField userTF = new TextField(10);
        TextField passTF = new TextField(10);
        JButton loginB = new JButton("Login");
        //loginB.setPreferredSize(new Dimension(10,40));
        
        //splash screen
        ImageIcon icon = createImageIcon("logo.jpg");
        JLabel splashL = new JLabel(icon, JLabel.CENTER);
                
        //userTF panel
        JPanel userTFP = new JPanel();
        userTFP.setLayout(new FlowLayout());
        userTFP.add(userTF);
        
        //passTF panel
        JPanel passTFP = new JPanel();
        passTFP.setLayout(new FlowLayout());
        passTFP.add(passTF);
        
        //login button panel
        JPanel loginBP = new JPanel();
        loginBP.setLayout(new FlowLayout());
        loginBP.add(loginB);
        
        //main panel
        JPanel mainP = new JPanel();
        mainP.setLayout(new GridLayout(1,5));
        mainP.add(userL);
        mainP.add(userTFP);
        mainP.add(passL);
        mainP.add(passTFP);
        mainP.add(loginBP);
                
        //border for login panel
        Border loginborder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "User Login" );
        mainP.setBorder(loginborder);
        
        //main container
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());
        pane.add(splashL, BorderLayout.CENTER);
        pane.add(mainP, BorderLayout.SOUTH);                
        
    }
    
    
    //confirmation window call
    private class confirmationwindow extends WindowAdapter {        
        public void windowClosing(WindowEvent e) {            
            
            int r = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Records Retention Database", JOptionPane.YES_NO_OPTION);
            if (r == JOptionPane.YES_OPTION)
                System.exit(0);
                //dispose();
       }
    }
    
        
    
    public static void main(String [] args) {
        main_interface login = new main_interface();
        login.setTitle("Records Retention Database Login");
        login.setVisible(true);
        login.setSize(600, 400);
    }
    
}
Force Flow is offline   Reply With Quote
Old 06-03-2004, 03:30 PM   #3
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
Nevermind guys, I got it. I had to specify the directory path.
Force Flow is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:55 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2