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