<import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;
//import com.mysql.jdbc.*;
public class Courier
{
public static void main(String [] a) throws SQLException
{
Myframe frame=new Myframe();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
MainPanel panel=new MainPanel();
/* These are for database
java.sql.Connection conn=null;
ResultSet result=null;
Statement stmt=null;
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Database name","username","password");
java.sql.Statement stm=conn.createStatement();
ResultSet rs = stm.executeQuery("SELECT * FROM offices");
// */
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
second main panel:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.border.*;
public class MainPanel extends JPanel
{ private JLabel banner,body,user_id,passwords;
private BufferedImage myHeader=null,myBody=null;
private JButton buttonOk, buttonCancel;
private JTextField username;
private JTextArea text;
private JPasswordField pass_field;
private JPanel pnltext,pnluser, pnlpass, pnlButton, pnlbox;
char[] cmd;
String user_name=" ",user_input=" ";
public MainPanel()
{ pass_field=new JPasswordField(10);
username=new JTextField(10);
buttonOk=new JButton("OK");
buttonCancel=new JButton("Cancel");
user_id=new JLabel("User Id:");
passwords=new JLabel("Password:");
ButtonListener listener=new ButtonListener();
buttonOk.addActionListener(listener);
buttonCancel.addActionListener(listener);
Font myFont=new Font("Cooper Black", Font.PLAIN,15);
text=new JTextArea("Enter your user ID and password here:");
pnlbox= new JPanel();
pnlbox.setLayout(new BoxLayout(pnlbox,BoxLayout.Y_AXIS));
pnlbox.setBackground(Color.white);
pnlbox.setAlignmentX(CENTER_ALIGNMENT);
pnltext=new JPanel();
pnltext.setLayout(new BoxLayout(pnltext,BoxLayout.X_AXIS));
pnltext.setBackground(Color.white);
pnluser=new JPanel();
pnluser.setLayout(new BoxLayout(pnluser,BoxLayout.X_AXIS));
pnluser.setBackground(Color.white);
pnluser.setAlignmentX(CENTER_ALIGNMENT);
pnlpass=new JPanel();
pnlpass.setLayout(new BoxLayout(pnlpass,BoxLayout.X_AXIS));
pnlpass.setBackground(Color.white);
pnlpass.setAlignmentX(CENTER_ALIGNMENT);
pnlButton=new JPanel();
pnlButton.setBackground(Color.white);
pnlbox.setBorder(BorderFactory.createTitledBorder( null,"Login Panel", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, myFont));
pnltext.add(text);
pnluser.add(user_id);
pnluser.add(Box.createRigidArea(new Dimension (30,10)));
pnluser.add(username);
pnlpass.add(passwords);
pnlpass.add(Box.createRigidArea(new Dimension (11,0)));
pnlpass.add(pass_field);
pnlButton.add(buttonOk);
pnlButton.add(buttonCancel);
pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
pnlbox.add(pnltext);
pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
pnlbox.add(pnluser);
pnlbox.add(Box.createRigidArea(new Dimension (20,10)));
pnlbox.add(pnlpass);
pnlbox.add(Box.createRigidArea(new Dimension (0,5)));
pnlbox.add(pnlButton);
try
{ myHeader = ImageIO.read(new File("Resized-SX2HH.jpg"));
myBody=ImageIO.read(new File("body.jpg"));
}
catch (IOException e){}
banner=new JLabel(new ImageIcon(myHeader));
body=new JLabel(new ImageIcon(myBody));
body.setAlignmentX(LEFT_ALIGNMENT);
Panel pnlheader=new Panel();
pnlheader.setLayout(new BorderLayout());
pnlheader.setLocation(10,35);
pnlheader.add(banner, BorderLayout.NORTH);
pnlheader.add(body, BorderLayout.WEST);
pnlheader.add(pnlbox, BorderLayout.EAST);
add(pnlheader);
setPreferredSize (new Dimension(1357,1100));
}
private class ButtonListener implements ActionListener, MouseListener
{
public void actionPerformed(ActionEvent e)
{ user_name=username.getText(); //user input username
cmd=pass_field.getPassword();
user_input=new String(cmd); //user input password here
if (e.getSource()==buttonOk)
{
JOptionPane.showMessageDialog(null, "Welcome ");
}
else
System.exit(0);
}
public void mousePressed(MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
public void mouseClicked(MouseEvent e){ }
public void mouseEntered(MouseEvent e)
{
if (e.getSource()==buttonOk)
buttonOk.setBackground(Color.green);
}
public void mouseExited(MouseEvent e)
{
if (e.getSource()==buttonOk) //Color color = new Color(204,204,204);
buttonOk.setBackground(null);
}
}
} >