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

📄 supplyclient.java

📁 RMI asynchronism receive message callback() register and deregister to control update or interrupt
💻 JAVA
字号:
package client;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

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

import both.Stock;

public class SupplyClient extends JFrame implements ActionListener{
    private static final long serialVersionUID = 1L;
    private JLabel lm = new JLabel("Supply Client");
    private Font f=new Font("TimesNewRoman",Font.BOLD,24);
    private JLabel l1 = new JLabel("Stock Symbol");
    private JLabel l2 = new JLabel("Value");
    private JTextField t1 = new JTextField();
    private JTextField t2 = new JTextField();
    private JButton b = new JButton("Send");

    public SupplyClient() {
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	this.setLayout(null);
    	lm.setFont(f);
    	this.add(lm); lm.setBounds(50,10,200,30);
    	this.add(l1); l1.setBounds(30,50,100,30);
    	this.add(t1); t1.setBounds(30,90,200,30);
    	this.add(l2); l2.setBounds(30,130,100,30);
    	this.add(t2); t2.setBounds(30,170,200,30);
    	this.add(b); b.setBounds(90,220,90,30);
        b.addActionListener(this);
		setSize(280,300);
		setVisible(true);
    }
    public void actionPerformed(ActionEvent evt) {
    	Object source = evt.getSource();
		if (source == b){
			try {
				Registry registry = LocateRegistry.getRegistry(null);
				Stock a = (Stock) registry.lookup("Stock");
				String stockSymbol = t1.getText();
				int value = Integer.parseInt(t2.getText());
				a.send( stockSymbol, value);
			} catch (Exception e) {
				System.err.println("Client exception: " + e.toString());
				e.printStackTrace();}}
	}
	public static void main(String[] args) {
		System.out.println("Sender Ready");
		new SupplyClient();}
}

⌨️ 快捷键说明

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