日期:2014-05-20  浏览次数:20644 次

用什么办法可以消除“游戏结束”这几个字被覆盖的
用什么办法可以消除“游戏结束”这几个字被覆盖的

------解决方案--------------------
try it

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

public class DelayedPaint {

    private CenterPanel center;
    private JFrame frame;
    private JPanel panel;

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new DelayedPaint().createAndShowGUI();
            }
        });
    }

    void createAndShowGUI() {
        frame = new JFrame("Delayed Paint");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        panel = new JPanel(new BorderLayout());
        frame.setContentPane(panel);
        NorthPanel north = new NorthPanel();
        panel.add(north, BorderLayout.NORTH);
        center = new CenterPanel();
        panel.add(center, BorderLayout.CENTER);
        frame.setVisible(true);
        north.startTimer();
    }

    class NorthPanel extends JPanel {

        private JLabel lb;

        public NorthPanel() {
            lb = new JLabel("Good morning");
            add(lb);
        }

        public void startTimer() {
            ActionListener taskPerformer = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    setLayout(new FlowLayout(FlowLayout.LEFT));
                    lb.setText("Left");
//    timer.stop(); // Not needed if setRepeats(false).