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

📄 link.java

📁 用java实现网页连接选单.等待您的回复
💻 JAVA
字号:
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.StringTokenizer;
import java.util.Vector;

public class link extends Applet
{

    public int number = 0;
    public Vector urls = null;
    public Vector names = null;
    public URL theURL = null;
    String at = null;
    StringTokenizer st = null;
    StringTokenizer str = null;
    String targetFrame = null;
    Color bgColor = null;
    String s = null;
    String rgbDelimiter = null;

    public void init()
    {
    	
        s = getParameter("bgColor");
        if(s != null)
            st = new StringTokenizer(s, rgbDelimiter);
        if(s == null)
            bgColor = Color.lightGray;
        else
        if(s.equalsIgnoreCase("red"))
            bgColor = Color.red;
        else
        if(s.equalsIgnoreCase("blue"))
            bgColor = Color.blue;
        else
        if(s.equalsIgnoreCase("green"))
            bgColor = Color.green;
        else
        if(s.equalsIgnoreCase("yellow"))
            bgColor = Color.yellow;
        else
        if(s.equalsIgnoreCase("white"))
            bgColor = Color.white;
        else
        if(s.equalsIgnoreCase("orange"))
            bgColor = Color.orange;
        else
        if(s.equalsIgnoreCase("cyan"))
            bgColor = Color.cyan;
        else
        if(s.equalsIgnoreCase("magenta"))
            bgColor = Color.magenta;
        else
        if(s.equalsIgnoreCase("black"))
            bgColor = Color.black;
        else
        if(st.countTokens() == 3)
        {
        	
            Integer integer = new Integer(st.nextToken());
            Integer integer1 = new Integer(st.nextToken());
            Integer integer2 = new Integer(st.nextToken());
            bgColor = new Color(integer.intValue(),
            integer1.intValue(), integer2.intValue());
            
        }
        else
        {
        	
            bgColor = Color.lightGray;
            
        }
        String s1 = getParameter("target");
        if(s1 != null)
            targetFrame = s1;
        else
            targetFrame = "_parent";
        String s2 = getParameter("number");
        number = Integer.parseInt(s2);
        Choice choice = new Choice();
        for(int i = 0; i <= number; i++)
        {
        	
            at = getParameter("link" + i);
            str = new StringTokenizer(at, "\\");
            names.addElement(new String(str.nextToken()));
            urls.addElement(new String(str.nextToken()));
            choice.addItem((String)names.elementAt(i));
            
        }

        add(choice);
        setBackground(bgColor);
        
    }

    public boolean action(Event event, Object obj)
    {
    	
        if(event.target instanceof Choice)
        {
        	
            String s1 = (String)obj;
            for(int i = 0; i <= number; i++)
                if(s1.equals((String)names.elementAt(i)))
                {
                	
                    try
                    {
                    	
                        theURL = new URL((String)urls.elementAt(i));
                        
                    }
                    catch(MalformedURLException _ex)
                    {
                    	
                        System.out.println("Bad URL");
                        
                    }
                    getAppletContext().showDocument(theURL,
                    targetFrame);
                    
                }

        }
        return true;
        
    }

    public link()
    {
    	
        urls = new Vector();
        names = new Vector();
        rgbDelimiter = ":,.";
        
    }
    
}

⌨️ 快捷键说明

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