一网页中嵌入一个Applet,Applet在网页中长为300,宽为400,Applet上有两个Jlabel对象lblName及lblWelcome,一个JTextField对象txtName和一个Jb

一网页中嵌入一个Applet,Applet在网页中长为300,宽为400,Applet上有两个Jlabel对象lblName及lblWelcome,一个JTextField对象txtName和一个Jbutton对象bttnWelcome,lblName显示“请输入你的姓名”,txtName为客户输入姓名,例如:Zhang san,当点击bttnWelcome,lblWelcome将要显示“Welcome Zhang san !”。

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Welcom extends JApplet 
{
     
	JPanel panel;
	JLabel lblName;
    JLabel lblWelcome;    
	JTextField txtName;	
	JButton bttnWelcome;		
	GridLayout gl; 
	
	public void init()
	{
     
    	panel=new JPanel();
        panel=(JPanel)getContentPane();
        gl=new GridLayout(2,2);
        panel.setLayout(gl);
        
        lblName=new JLabel("请输入你的姓名");
        txtName=new JTextField(10);
        bttnWelcome=new JButton("Welcome");
        lblWelcome=new JLabel();
        
        panel.add(lblName);
        panel.add(txtName);
        panel.add(bttnWelcome);
        panel.add(lblWelcome);        
		
		WelcomeAction welcome = new WelcomeAction();
		bttnWelcome.addActionListener(welcome);	
	}
	class WelcomeAction implements ActionListener
	{
     
		public void actionPerformed(ActionEvent evt)
		{
     		
			Object obj = evt.getSource();
			if(obj == bttnWelcome)
			{
     
				String str = txtName.getText();
				lblWelcome.setText("Welcome" + str);				
			}	  	          
		}
	}
}


<html>
<applet code="Welcom.class" width=300 height=400>
</applet>
</html>

你可能感兴趣的:(JAVA编程,html5,js)