1 Replies - 4875 Views - Last Post: 19 April 2008 - 05:09 AM Rate Topic: -----

#1 lola_198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-April 08

GUI email interface

Posted 18 April 2008 - 11:41 PM

can someone show me how to display error msg from another customised exception class using the exception1Label... should i use override or something else instead

Email : [textbox]
[errorMsg if wrong email format is entered, appear invisble at first]
Password : [textbox]
[errorMsg if wrong password is entered, appear invisble at first]




 public class Login extends JFrame {
	
	private static final int WIDTH = 400;
	private static final int HEIGHT = 200;
	
	private JLabel emailLabel, passwordLabel, exception1Label, exception2Label, blank1Label, blank2Label;
	private JTextField emailTextField, passwordTextField;
	private JButton loginB, cancelB;
	
	private LoginButtonHandler	loginbHandler;
	private CancelButtonHandler	cancelbHandler;
	
	static String email = "", password = "", errorMsg1, errorMsg2;

	public Login() {
		
		setTitle("Login");
		setSize(WIDTH, HEIGHT);
		
		emailLabel = new JLabel("Email: " );
		blank1Label = new JLabel("");
		exception1Label = new JLabel(errorMsg1);
		passwordLabel = new JLabel("Password: ");
		blank2Label = new JLabel("");
		exception2Label = new JLabel(errorMsg2);
		
		emailTextField = new JTextField();
		passwordTextField = new JTextField();
		
		loginB = new JButton("Login");
		loginbHandler = new LoginButtonHandler();
		loginB.addActionListener(loginbHandler);
		
		cancelB = new JButton("Cancel");
		cancelbHandler = new CancelButtonHandler();
		cancelB.addActionListener(cancelbHandler);
		
		Container pane = getContentPane();
		
		GridLayout gridLayout = new GridLayout (4,2);
		FlowLayout flowLayout = new FlowLayout();
		
		JPanel northPanel = new JPanel();
		JPanel southPanel = new JPanel();
		
		northPanel.setLayout(gridLayout);
		southPanel.setLayout(flowLayout);
		
		northPanel.add(emailLabel);
		northPanel.add(emailTextField);
		northPanel.add(blank1Label);
		northPanel.add(exception1Label);
		northPanel.add(passwordLabel);
		northPanel.add(passwordTextField);
		northPanel.add(blank2Label);
		northPanel.add(exception2Label);
		
		southPanel.add(loginB);
		southPanel.add(cancelB);
		
		pane.add (northPanel, BorderLayout.NORTH);
		pane.add (southPanel, BorderLayout.SOUTH);
		
		centerFrame (WIDTH, HEIGHT);
	}
	
	public void centerFrame(int frameWidth, int frameHeight) {
		
		Toolkit aToolkit = Toolkit.getDefaultToolkit();
		
		Dimension screen = aToolkit.getScreenSize();
		
		int xPositionOfFrame = (screen.width - frameWidth) / 2;
		int yPositionOfFrame = (screen.height - frameHeight) / 2;
	
		setBounds(xPositionOfFrame, yPositionOfFrame, frameWidth, frameHeight);
	} 


Is This A Good Question/Topic? 0
  • +

Replies To: GUI email interface

#2 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: GUI email interface

Posted 19 April 2008 - 05:09 AM

Well one way would be to:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Login extends JFrame {
	private static final long serialVersionUID = -7496192562700309096L;
	private static final int WIDTH = 400;
    private static final int HEIGHT = 200;
    
    private JLabel emailLabel, passwordLabel, exception1Label, exception2Label, blank1Label, blank2Label;
    private JTextField emailTextField, passwordTextField;
    private JButton loginB, cancelB;
    
	class MyMouseAdapter extends MouseAdapter{
		private JLabel _msg_panel;
		private String _msg_value;

		MyMouseAdapter(JLabel msg_panel, String msg_value) {
			this._msg_panel = msg_panel;
			this._msg_value = msg_value;
		}

		public void mousePressed(MouseEvent e) {
			this._msg_panel.setText(_msg_value);
		}
	}
	
    private MyMouseAdapter    loginbHandler;
    private MyMouseAdapter    cancelbHandler;
    
    static String email = "", password = "", errorMsg1, errorMsg2;

    public Login() {
        
        setTitle("Login");
        setSize(WIDTH, HEIGHT);
        
        emailLabel = new JLabel("Email: " );
        blank1Label = new JLabel("");
        exception1Label = new JLabel(errorMsg1);
        passwordLabel = new JLabel("Password: ");
        blank2Label = new JLabel("");
        exception2Label = new JLabel(errorMsg2);
        
        emailTextField = new JTextField();
        passwordTextField = new JTextField();
        
        loginB = new JButton("Login");
        loginbHandler = new MyMouseAdapter(exception1Label, "Some login msg");
        loginB.addMouseListener(loginbHandler);
        
        cancelB = new JButton("Cancel");
        cancelbHandler = new MyMouseAdapter(exception1Label, "Some cancel msg");
        cancelB.addMouseListener(cancelbHandler);
        
        Container pane = getContentPane();
        
        GridLayout gridLayout = new GridLayout (4,2);
        FlowLayout flowLayout = new FlowLayout();
        
        JPanel northPanel = new JPanel();
        JPanel southPanel = new JPanel();
        
        northPanel.setLayout(gridLayout);
        southPanel.setLayout(flowLayout);
        
        northPanel.add(emailLabel);
        northPanel.add(emailTextField);
        northPanel.add(blank1Label);
        northPanel.add(exception1Label);
        northPanel.add(passwordLabel);
        northPanel.add(passwordTextField);
        northPanel.add(blank2Label);
        northPanel.add(exception2Label);
        
        southPanel.add(loginB);
        southPanel.add(cancelB);
        
        pane.add (northPanel, BorderLayout.NORTH);
        pane.add (southPanel, BorderLayout.SOUTH);
        
        centerFrame (WIDTH, HEIGHT);
    }
    
    public void centerFrame(int frameWidth, int frameHeight) {
        
        Toolkit aToolkit = Toolkit.getDefaultToolkit();
        
        Dimension screen = aToolkit.getScreenSize();
        
        int xPositionOfFrame = (screen.width - frameWidth) / 2;
        int yPositionOfFrame = (screen.height - frameHeight) / 2;
    
        setBounds(xPositionOfFrame, yPositionOfFrame, frameWidth, frameHeight);
    }
} 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1