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

📄 starmenu.java

📁 Java 范例实战 光盘使用说明 ========================== 本光盘的文件结构如下所示: =====================================
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

public class starmenu extends Applet
    implements Runnable
{

    AppletContext appletcontrol = null;
    private Graphics g2 = null;
    private Graphics g = null;
    boolean isanimated = false;
    private Thread program_thread = null;
    private int fontsize = 0;
    private int space = 0;
    private int displace = 0;
    private int i = 0;
    private int j = 0;
    private int mult = 0;
    private int sel = 0;
    private int blink = 0;
    private int oldsel = 0;
    private int sel2 = 0;
    private int savedtime = 0;
    private String target = null;
    private Font font = null;
    private Image bufferscreen = null;
    private Dimension d = null;
    private Color backgroundcolor = null;
    private Color foregroundcolor = null;
    private Color shadowcolor = null;
    double alpha = 0;
    private long enabledtime = 0;
    String items[] = null;
    private boolean registered = false;
    String urls[] = null;
    int maxitems = 0;
    boolean notready = false;

    public void init()
    {

        super.init();
        setLayout(null);
        addNotify();
        d = getSize();
        prepareVariables();
        isanimated = false;
        blink = -1;
        space = fontsize + 9;
        bufferscreen = createImage(d.width, d.height);
        appletcontrol = getAppletContext();
        g = bufferscreen.getGraphics();
        g2 = getGraphics();
        g.setFont(font);
        g2.setFont(font);

    }

    public boolean handleEvent(Event event)
    {

        return super.handleEvent(event);

    }

    public int stylecheck()
    {

        int k = 0;
        String s = getParameter("italic");
        s = s.toLowerCase();
        if(s.charAt(0) == 'y')
            k = 2;
        s = getParameter("bold");
        s = s.toLowerCase();
        if(s.charAt(0) == 'y')
            k++;
        return k;

    }

    int getParameter(String s1, int s2) 
    {
    
        String s = getParameter(s1) ;
        return (s != null) ? Integer.parseInt(s) : s2 ;
    
    }

    Color getParameter(String s1, Color s2)
    {
    
        String s = getParameter(s1);
        return (s != null) ? new Color(Integer.parseInt(s, 16)):s2;
    
    }
    
    public void prepareVariables()
    {
        
        fontsize = getParameter("fontsize", 16);
        font = new Font(getParameter("font"), 
                        stylecheck(), 
                        fontsize);
        resize(getSize().width, getSize().height);
        target = getParameter("target");
        displace = getParameter("displace", 2);
        d = getSize();
        bufferscreen = createImage(d.width, d.height);
        appletcontrol = getAppletContext();
        backgroundcolor = getParameter("background", Color.black);
        foregroundcolor = getParameter("foreground", Color.white);
        shadowcolor = getParameter("shadow", Color.gray);
        String s = "";
        maxitems = -1;
        String s1;
        for(; s != null; s = getParameter("item" + s1))
        {
        
            maxitems++;
            s1 = String.valueOf(maxitems);
        
        }

        urls = new String[maxitems];
        items = new String[maxitems];
        for(i = 0; i < maxitems; i++)
        {
        
            String s2 = String.valueOf(i);
            urls[i] = getParameter("url" + s2);
            items[i] = getParameter("item" + s2);
        
        }

        g2 = getGraphics();
        g = bufferscreen.getGraphics();
    
    }

    public void drawitems(int k, int l, boolean flag)
    {
    
        if(!flag)
            blink = -1;
        for(int i1 = 0; i1 < k; i1++)
        {
    
            g.setColor(backgroundcolor);
            g.fillRect(0, 0, d.width, d.height);
            FontMetrics fontmetrics = g.getFontMetrics(font);
            for(int j1 = 0; j1 < l; j1++)
            {
                
                int k1 = d.width / 2 - 
                    fontmetrics.stringWidth(items[j1]) / 2;
                g.setColor(shadowcolor);
                if(sel2 == j1 && blink == 1)
                    g.setColor(backgroundcolor);
                g.drawString(items[j1], k1 + 
                    displace, j1 * space + space + displace);
                g.setColor(foregroundcolor);
                if(sel2 == j1 && blink == 1)
                    g.setColor(backgroundcolor);
                g.drawString(items[j1], k1, j1 * space + space);
            
            }

            if(flag)
                blink *= -1;
            g2.drawImage(bufferscreen, 0, 0, this);
            try
            {
            
                Thread.sleep(70L);
            
            }
            catch(InterruptedException _ex) { }
        
        }

    }

    public boolean mouseMove(Event event, int k, int l)
    {
        
        int which_one = l / space; 
        showStatus(urls[which_one]);  
        return true;             	
   
    }	
    
    public boolean mouseExit(Event event, int k, int l)
    {
   
    	showStatus(""); 
    	return true;
   
    }
    	
    public boolean mouseDown(Event event, int k, int l)
    {
   
        if(!notready)
        {
   
            int which_one = l / space;
            if(which_one < maxitems)
            {
   
                oldsel = sel2;
                sel2 = which_one; 
                if(sel2 > -1 && sel2 < maxitems)
                {
   
                    g2.drawImage(bufferscreen, 0, 0, this);
                    drawitems(6, maxitems, true);
                    drawitems(1, maxitems, false);
                    URL url;
                    try
                    {
   
                        url = new URL(urls[sel2]);
   
                    }
                    catch(MalformedURLException _ex)
                    {
   
                        return true;
   
                    }
                    appletcontrol.showDocument(url, target);
   
                }
   
            }
   
        }
        return true;
   
    }

    public void paint(Graphics g1)
    {
   
        if(!notready)
        {
   
            drawitems(1, maxitems, false);
            return;
   
        }
   
    }

    public void update(Graphics g1)
    {
   
        paint(g1);
   
    }

    public void syncsleep(int k)
    {
   
        if(k > -1)
        {
   
            enabledtime = System.currentTimeMillis();
            savedtime = k;
            return;
   
        }
        try
        {
   
            Thread.sleep(Math.max((long)savedtime - 
                        (System.currentTimeMillis() - 
                        enabledtime), 4L));
            return;
   
        }
        catch(InterruptedException _ex)
        {
   
            return;
   
        }
   
    }

    public void start()
    {
   
        if(program_thread == null)
        {
   
            program_thread = new Thread(this);
            program_thread.start();
   
        }
   
    }

    public void stop()
    {
   
        if(program_thread != null && program_thread.isAlive())
            program_thread.stop();
   
        program_thread = null;
    }

    public void run()
    {
   
        if(!isanimated)
        {
   
            i = 0;
            j = 0;
            oldsel = 0;
            sel2 = 0;
            notready = true;
            g2.drawImage(bufferscreen, 0, 0, this);
            g.setColor(backgroundcolor);
            g.fillRect(0, 0, d.width, d.height);
            g.getFontMetrics(font);
            for(i = 0; i < maxitems; i++)
            {

                for(j = 0; j < fontsize - 3; j++)
                {
   
                    g.setColor(backgroundcolor);
                    g.fillRect(0, i * space + space / 2, 
                               d.width, d.height);
                    g2.drawImage(bufferscreen, 0, 0, this);
                    try
                    {
   
                        Thread.sleep(20L);
   
                    }
                    catch(InterruptedException _ex) { }
                    
                }
                drawitems(1, i + 1, false);
           
            }

            g2.drawImage(bufferscreen, 0, 0, this);
            isanimated = true;
            notready = false;
            return;
        
        }
    }

}

⌨️ 快捷键说明

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