博文

目前显示的是标签为“swing”的博文

Swing repaint() problem

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.BorderLayout; public class MovingBall extends JFrame { private int ballPositionX; private int ballPositionY; private JButton controlButton; private MyDrawPanel drawArea; public MovingBall() { ballPositionX = 70; ballPositionY = 70; controlButton = new JButton("play"); controlButton.addActionListener(new ButtonHandler()); BorderLayout buttonLayout = new BorderLayout(); this.getContentPane().add(controlButton, buttonLayout.SOUTH); drawArea = new MyDrawPanel(); BorderLayout drawAreaLayout = new BorderLayout(); this.getContentPane().add(drawArea, drawAreaLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(500, 500); this.setVisible(true); } private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event) { go(); } } private class MyDrawPanel extends JPane...