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

📄 sender.java

📁 java applet编程,实现对相关图片声音的调用
💻 JAVA
字号:
import java.applet.*;import java.awt.*;import java.awt.event.*;import java.util.Enumeration;public class Sender extends Applet implements ActionListener{    private String myName;    private TextField nameField;    private TextArea status;    private String newline;    public void init()	{        setLayout( new BorderLayout() );        Panel p;		p = new Panel();        Label receiverLabel = new Label("Receiver name:", Label.RIGHT);        p.add(receiverLabel);        nameField = new TextField(getParameter("receiverName"), 10);        nameField.addActionListener(this);        p.add(nameField);        Button button = new Button("Send message");        button.addActionListener(this);        p.add(button);		add(p, "North");        status = new TextArea(5, 60);        status.setEditable(false);        add(status, "Center");        myName = getParameter("myU");        Label senderLabel = new Label("(My name is " + myName + ".)", Label.CENTER);        add(senderLabel, "South");		newline = System.getProperty("line.separator");    }    public void actionPerformed(ActionEvent event)	{        Applet receiver = null;        String receiverName = nameField.getText(); //Get name to                                                    //search for.        receiver = getAppletContext().getApplet(receiverName);        if (receiver != null)		{            //Use the instanceof operator to make sure the applet            //we found is a Receiver object.            if (!(receiver instanceof Receiver))			{                status.append("Found applet named "                              + receiverName + ", "                              + "but it's not a Receiver object."						      + newline);            }			else			{                status.append("Found applet named "                              + receiverName + newline                              + "  Sending message to it."						      + newline);                //Cast the receiver to be a Receiver object                //(instead of just an Applet object) so that the                //compiler will let us call a Receiver method.                ((Receiver)receiver).processRequestFrom(myName);            }        }		else		{            status.append("Couldn't find any applet named "                          + receiverName + "." + newline);        }    }    public Insets getInsets()	{        return new Insets(3,3,3,3);    }    public void paint(Graphics g)	{        g.drawRect(0, 0,                    getSize().width - 1, getSize().height - 1);    }    public String getAppletInfo()	{        return "Applet Sender by lyw.";    }}

⌨️ 快捷键说明

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