11 个解决方案
#1
repaint()方法会执行:update()方法,先刷新屏幕(以背景填充),在调用
paint()方法重画。
一般可以重载update()和paint()方法。
paint()方法重画。
一般可以重载update()和paint()方法。
#2
repaint()调用paint(),在APPLET中,可根据自己意图改写paint().
#3
To get rid of the flicker, override update() as follows:
public void update(Graphics g) {
paint(g);
}
public void update(Graphics g) {
paint(g);
}
#4
问题可能在代码,能看看吗?
#5
to lmy2000:
repaint()方法应该写在哪里才能在我移动Panel时调用repaint()?
repaint()方法应该写在哪里才能在我移动Panel时调用repaint()?
#6
另外:我的repaint()方法是在事件处理时才触发的,如何还要保证在屏幕刷新时也触发repaint()方法呢?
#7
paint画的图会被子控件覆盖!
#8
to wangtaoyy:
void myActionListener_actionPerformed(ActionEvent e)
{
repaint(g, x, y, width, height, startAngle, arcAngle, Color.orange);
}
repaint()方法中重载update(),update()中重载paint()
void myActionListener_actionPerformed(ActionEvent e)
{
repaint(g, x, y, width, height, startAngle, arcAngle, Color.orange);
}
repaint()方法中重载update(),update()中重载paint()
#9
使用轻量组件
或重载getInsets()返回合适的值。
或重载getInsets()返回合适的值。
#10
Applet子类完全正常
JApplet的子类要在paint方法中先调用父类的paint
以下Applet运行正常
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
button1.setLabel("draw");
add(button1);
button1.setBackground(java.awt.Color.lightGray);
button1.setBounds(252,48,112,47);
SymAction lSymAction = new SymAction();
button1.addActionListener(lSymAction);
}
java.awt.Button button1 = new java.awt.Button();
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == button1)
button1_ActionPerformed(event);
}
}
void button1_ActionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
g.drawRect(20, 20, 100, 100);
}
}
//
以下JApplet运行正常
import java.awt.*;
import javax.swing.*;
/**
* A basic extension of the javax.swing.JApplet class
*/
public class JApplet1 extends JApplet
{
public void init()
{
getContentPane().setLayout(null);
setSize(426,266);
JButton1.setText("draw");
getContentPane().add(JButton1);
JButton1.setBounds(300,108,71,46);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
JButton1.addActionListener(lSymAction);
//}}
}
//{{DECLARE_CONTROLS
javax.swing.JButton JButton1 = new javax.swing.JButton();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == JButton1)
JButton1_actionPerformed(event);
}
}
void JButton1_actionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
super.paint(g);
g.drawRect(20, 20, 100, 100);
}
}
JApplet的子类要在paint方法中先调用父类的paint
以下Applet运行正常
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
button1.setLabel("draw");
add(button1);
button1.setBackground(java.awt.Color.lightGray);
button1.setBounds(252,48,112,47);
SymAction lSymAction = new SymAction();
button1.addActionListener(lSymAction);
}
java.awt.Button button1 = new java.awt.Button();
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == button1)
button1_ActionPerformed(event);
}
}
void button1_ActionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
g.drawRect(20, 20, 100, 100);
}
}
//
以下JApplet运行正常
import java.awt.*;
import javax.swing.*;
/**
* A basic extension of the javax.swing.JApplet class
*/
public class JApplet1 extends JApplet
{
public void init()
{
getContentPane().setLayout(null);
setSize(426,266);
JButton1.setText("draw");
getContentPane().add(JButton1);
JButton1.setBounds(300,108,71,46);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
JButton1.addActionListener(lSymAction);
//}}
}
//{{DECLARE_CONTROLS
javax.swing.JButton JButton1 = new javax.swing.JButton();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == JButton1)
JButton1_actionPerformed(event);
}
}
void JButton1_actionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
super.paint(g);
g.drawRect(20, 20, 100, 100);
}
}
#11
thanks, i see
#1
repaint()方法会执行:update()方法,先刷新屏幕(以背景填充),在调用
paint()方法重画。
一般可以重载update()和paint()方法。
paint()方法重画。
一般可以重载update()和paint()方法。
#2
repaint()调用paint(),在APPLET中,可根据自己意图改写paint().
#3
To get rid of the flicker, override update() as follows:
public void update(Graphics g) {
paint(g);
}
public void update(Graphics g) {
paint(g);
}
#4
问题可能在代码,能看看吗?
#5
to lmy2000:
repaint()方法应该写在哪里才能在我移动Panel时调用repaint()?
repaint()方法应该写在哪里才能在我移动Panel时调用repaint()?
#6
另外:我的repaint()方法是在事件处理时才触发的,如何还要保证在屏幕刷新时也触发repaint()方法呢?
#7
paint画的图会被子控件覆盖!
#8
to wangtaoyy:
void myActionListener_actionPerformed(ActionEvent e)
{
repaint(g, x, y, width, height, startAngle, arcAngle, Color.orange);
}
repaint()方法中重载update(),update()中重载paint()
void myActionListener_actionPerformed(ActionEvent e)
{
repaint(g, x, y, width, height, startAngle, arcAngle, Color.orange);
}
repaint()方法中重载update(),update()中重载paint()
#9
使用轻量组件
或重载getInsets()返回合适的值。
或重载getInsets()返回合适的值。
#10
Applet子类完全正常
JApplet的子类要在paint方法中先调用父类的paint
以下Applet运行正常
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
button1.setLabel("draw");
add(button1);
button1.setBackground(java.awt.Color.lightGray);
button1.setBounds(252,48,112,47);
SymAction lSymAction = new SymAction();
button1.addActionListener(lSymAction);
}
java.awt.Button button1 = new java.awt.Button();
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == button1)
button1_ActionPerformed(event);
}
}
void button1_ActionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
g.drawRect(20, 20, 100, 100);
}
}
//
以下JApplet运行正常
import java.awt.*;
import javax.swing.*;
/**
* A basic extension of the javax.swing.JApplet class
*/
public class JApplet1 extends JApplet
{
public void init()
{
getContentPane().setLayout(null);
setSize(426,266);
JButton1.setText("draw");
getContentPane().add(JButton1);
JButton1.setBounds(300,108,71,46);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
JButton1.addActionListener(lSymAction);
//}}
}
//{{DECLARE_CONTROLS
javax.swing.JButton JButton1 = new javax.swing.JButton();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == JButton1)
JButton1_actionPerformed(event);
}
}
void JButton1_actionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
super.paint(g);
g.drawRect(20, 20, 100, 100);
}
}
JApplet的子类要在paint方法中先调用父类的paint
以下Applet运行正常
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
setLayout(null);
setSize(426,266);
button1.setLabel("draw");
add(button1);
button1.setBackground(java.awt.Color.lightGray);
button1.setBounds(252,48,112,47);
SymAction lSymAction = new SymAction();
button1.addActionListener(lSymAction);
}
java.awt.Button button1 = new java.awt.Button();
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == button1)
button1_ActionPerformed(event);
}
}
void button1_ActionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
g.drawRect(20, 20, 100, 100);
}
}
//
以下JApplet运行正常
import java.awt.*;
import javax.swing.*;
/**
* A basic extension of the javax.swing.JApplet class
*/
public class JApplet1 extends JApplet
{
public void init()
{
getContentPane().setLayout(null);
setSize(426,266);
JButton1.setText("draw");
getContentPane().add(JButton1);
JButton1.setBounds(300,108,71,46);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
JButton1.addActionListener(lSymAction);
//}}
}
//{{DECLARE_CONTROLS
javax.swing.JButton JButton1 = new javax.swing.JButton();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == JButton1)
JButton1_actionPerformed(event);
}
}
void JButton1_actionPerformed(java.awt.event.ActionEvent event)
{
repaint();
}
public void paint(Graphics g){
super.paint(g);
g.drawRect(20, 20, 100, 100);
}
}
#11
thanks, i see