|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Barefoot on the Moon!
Staff
Premium Member
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.
|
|
|
|
|
|
#2 |
|
Barefoot on the Moon!
Staff
Premium Member
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);
}
}
|
|
|
|
|
|
#3 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Nevermind guys, I got it. I had to specify the directory path.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|