frame5.java

来自「网上虚拟社区」· Java 代码 · 共 224 行

JAVA
224
字号


import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Point;
import java.rmi.Naming;
import javax.swing.ImageIcon;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Frame5 extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JButton jButton = null;

	private JButton jButton1 = null;

	private JLabel jLabel = null;

	private JTextField jTextField = null;

	private JPasswordField jPasswordField = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;
	
	private String name = null;
	private String url = null;
	
	private boolean isconnected = false;
	private CommunityServerInterface thecommunity; 

	/**
	 * This is the default constructor
	 */
	public Frame5() {
		super();
		initialize();
	}

	
	public Frame5(String Name,String Url) {
		super();
		name = Name;
		url = Url;
		initializeRMI();
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(282, 256);
		this.setLocation(new Point(300, 150));
		this.setContentPane(getJContentPane());
		this.setTitle("网上银行");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(58, 13, 146, 18));
			jLabel2.setIcon(new ImageIcon(getClass().getResource("/ball.jpg")));
			jLabel2.setText("网上银行登录:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(30, 91, 52, 22));
			jLabel1.setText("密码:");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(33, 40, 44, 24));
			jLabel.setText("帐户:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJButton1(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJPasswordField(), null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(33, 150, 84, 29));
			jButton.setText("登录");
			jButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jButtonActionPerformed(evt);
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(165, 153, 83, 30));
			jButton1.setText("取消");
			jButton1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jButton1ActionPerformed(evt);
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(105, 43, 142, 22));
		}
		return jTextField;
	}

	/**
	 * This method initializes jPasswordField	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new Rectangle(102, 90, 145, 22));
		}
		return jPasswordField;
	}

	private void jButton1ActionPerformed(ActionEvent evt) {
//		System.out.println("jButton1.actionPerformed, event=" + evt);
		this.setVisible(false);//TODO add your code for jButton1.actionPerformed
	}

	private void jButtonActionPerformed(ActionEvent evt) {
//		System.out.println("jButton.actionPerformed, event=" + evt);
//		TODO add your code for jButton.actionPerformed
		try{
			if(thecommunity.getpermission(jTextField.getText(), new String(jPasswordField.getPassword()), "Bank")){
			      this.setVisible(false);
		          Frame4 frame =new Frame4(jTextField.getText(), new String(jPasswordField.getPassword()),url);
//		          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		          frame.setVisible(true);	
			}
			else
				 JOptionPane.showMessageDialog(null,"Please enter right Message!","Message error",JOptionPane.ERROR_MESSAGE);			
		}
		catch(Exception ex){
			System.out.println(ex);
			 JOptionPane.showMessageDialog(null,"the net is busy, please retry!","Message error",JOptionPane.ERROR_MESSAGE);	
		}
	}
	
	protected boolean initializeRMI(){
		if(isconnected) return true;
		if(url.equals("default"))
			url = "";
		url = "rmi://"+url+"/";
		try{
			thecommunity = (CommunityServerInterface)Naming.lookup(url+"CommunityServerInterfaceImpl");
			System.out.println("Server object "+thecommunity+" found");
			isconnected = true;
			return true;
		}
		catch(Exception ex){
			System.out.println(url);
			System.out.println(ex);
			JOptionPane.showMessageDialog(null,"Please enter right ID!","ID error",JOptionPane.ERROR_MESSAGE);
			return false;
		}
	}

}  //  @jve:decl-index=0:visual-constraint="94,19"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?