我的按钮闪烁

时间:2016-05-28 00:05:27

标签: java button applet awt

我的按钮闪烁,我不知道为什么。当我单击公式按钮并设置NextPage和HomePage按钮可见时,NextPage按钮闪烁而HomePage没有。我可以点击按钮,如果我正确的话,然后LastButton有同样的问题闪烁

我检查是否是因为applet不断重新绘制,但这似乎不是问题。我真的很困惑为什么它会这样做,因为它不会不断刷新。

这是我的代码,并提前致谢。

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import javax.imageio.ImageIO;

public class Summative extends Applet
    implements ActionListener
{
    Button Formulas = new Button ("Formulas");
    Button StartQuiz = new Button ("Start Quiz");
    Button NextPage = new Button ("Next Page");
    Button LastPage = new Button ("Last Page");
    Button HomePage = new Button ("Home Page");
    boolean Formulae = false;
    boolean Start = false;
    boolean lesson = false;
    int count = 1;
    int i = 0;
    boolean Home = false;
    URL url;
    Image mathmeme1;
    Image background;
    int level = 0;
    public void init ()
    {
        this.setLayout (null);
        setSize (1280, 800);
        try
        {
            url = getDocumentBase ();
        }
        catch (Exception e)
        {
        }
        mathmeme1 = getImage (url, "MathMeme.jpg");
        background = getImage (url, "PIE.jpg");


        setBackground (Color.white);
        Formulas.addActionListener (this);
        StartQuiz.addActionListener (this);
        NextPage.addActionListener (this);
        LastPage.addActionListener (this);
        HomePage.addActionListener (this);
        add (Formulas);
        Formulas.setBounds (590, 200, 100, 40);
        add (StartQuiz);
        StartQuiz.setBounds (590, 300, 100, 40);
        add (NextPage);
        NextPage.setBounds (1180, 760, 100, 40);
        NextPage.setVisible (false);
        add (LastPage);
        LastPage.setBounds (0, 760, 100, 40);
        LastPage.setVisible (false);
        add (HomePage);
        HomePage.setBounds (590, 760, 100, 40);
        HomePage.setVisible (false);


    }


    public void paint (Graphics g)
    {
        g.setColor (Color.white);
        g.drawImage (background, 0, 0, this);
        if (Formulae == true)
        {
            g.drawString ("lesson" + count, 100, 100);
            if (count < 4)
                NextPage.setVisible (true);
            if (count > 1)
                LastPage.setVisible (true);
            HomePage.setVisible (true);
            Formulas.setVisible (false);
            StartQuiz.setVisible (false);
        }
        NextPage.setVisible (false);
        LastPage.setVisible (false);
        if (Home == true)
        {
            Formulae = false;
            lesson = false;
            count = 1;
            Formulas.setVisible (true);
            StartQuiz.setVisible (true);
            HomePage.setVisible (false);
        }
        g.fillRect(i, 1, 100, 100);
        g.drawString ("" + i, 100, 400);
        i++;
    }
    public void actionPerformed (ActionEvent evt)
    {
        if (evt.getSource () == Formulas)
        {
            Formulae = true;
            repaint ();
        }
        if (evt.getSource () == StartQuiz)
        {
            Start = true;
            repaint ();
        }
        if (evt.getSource () == NextPage)
        {
            count += 1;
            repaint ();
        }
        if (evt.getSource () == LastPage)
        {
            count -= 1;
            repaint ();
        }
        if (evt.getSource () == HomePage)
        {
            Home = true;
            repaint ();
        }
    }
}

0 个答案:

没有答案