Loans Bad Credit | Debt Help | Cell Phones | Loans | Dirty Dozen Brass Band
Having a problem making an image appear in a java applet [Archive] - PCMech Forums

PDA

View Full Version : Having a problem making an image appear in a java applet


Force Flow
06-02-2004, 12:10 PM
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.


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);
}

}

Force Flow
06-02-2004, 02:57 PM
I also tried this, but createImageIcon isn't being found for some reason. Does it need a specified package imported?

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
06-03-2004, 04:30 PM
Nevermind guys, I got it. I had to specify the directory path.