求帮忙看下JAVA中paint()的重写
这里该怎么修改呢?具体代码如下packagemy.test;importjava.awt.*;importjavax.swing.JPanel;publicclassTe...
这里该怎么修改呢?具体代码如下package my.test;import java.awt.*;import javax.swing.JPanel;public class TetrisPanel extends JPanel implements Runnable {public int ypos=-80;private Image iBuffer;private Graphics gBuffer; public TetrisPanel(){ Thread t =new Thread(this); t.start();}@Overridepublic void run() { while(true){ try{ Thread.sleep(30); } catch(InterruptedException e){ ypos = 5; if(ypos>300) ypos=-80; repaint(); } } public void paint(Graphics g){ g.setColor(Color.RED); g.fillOval(90, ypos, 80, 80); }}}package my.test;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class MyWindow extends JFrame { MyWindow(){ this.setTitle("这是测试窗口"); Container c = this.getContentPane(); c.add(new TetrisPanel()); this.setBounds(400, 200, 300, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setVisible(true); }public static void main(String[] args) { MyWindow DB=new MyWindow(); DB.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }}); }}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询