⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardclient.java

📁 J2EE之EJB,RMI多个源码
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class CardClient extends JFrame
{
	public static int w=690;
	public static int h=95;
	public static String str="Earnest Shopping Centre Welcomes You";
	Container c;
	
	JLabel lname,lcard,result;
	JTextField tname,tcard;
	JButton b;

      public int res;
      public static String uname;
     public static String ccno;


	public CardClient()
	{
		super(str);
		
		//The UI
		c=getContentPane();
		c.setLayout(new GridLayout(3,2,2,2));

		lname=new JLabel("Name:");
		c.add(lname);
		
		tname=new JTextField(20);
		c.add(tname);
		
		lcard=new JLabel("Card Number");
		c.add(lcard);
		
		tcard=new JTextField(16);
		c.add(tcard);

		b=new JButton("Submit");
		c.add(b);
		
		result=new JLabel();
		c.add(result);
		b.addActionListener(new addEvent());
		setSize(w,h);
		show();	
	}
	public class addEvent implements ActionListener
	{
	public void actionPerformed(ActionEvent evt)
  	{
   	uname= tname.getText();
	ccno=tcard.getText();
	try {
	
          Context initial = new InitialContext();
           Object objref = initial.lookup("CardJNDI");

           CardHome home = 
               (CardHome)PortableRemoteObject.narrow(objref,
                                            CardHome.class);

           Card Creditcard = home.create(uname,ccno);

	     res = Creditcard.validate(ccno);
	     if (res==0)
		{
	      result.setText("The card number " + ccno + " is valid!");
		}
		else
		{
		result.setText("Sorry! The card number " + ccno + " is invalid!");	
	            }
		}

       	 catch (Exception ex) {
	result.setText("Check if you have entered your name and also card number!");

  
   }
}

}
public static void main(String args[])
{
CardClient c;
c=new CardClient();
}
}

⌨️ 快捷键说明

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