当前位置: 技术问答>java相关
各位高手,我在applet里放了一个jpanel,在panel里add了一个按钮,又用panel.getgraphic.drawline,刷新后只有按钮,没有那条线了
来源: 互联网 发布时间:2015-05-12
本文导语: 请问如何才能2个都保留啊,我重写了paint,paintcomponent都不行,我又用updateUI,还是不能达到都保留的效果 | 看睛面的代码你就会明白了。 import java.applet.Applet; import java.awt.*; import java.awt.event.*...
请问如何才能2个都保留啊,我重写了paint,paintcomponent都不行,我又用updateUI,还是不能达到都保留的效果
|
看睛面的代码你就会明白了。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Polylines extends Applet {
private static Color[] colors = {
Color.white, Color.black, Color.blue, Color.red,
Color.yellow, Color.orange, Color.cyan, Color.pink,
Color.magenta, Color.green };
public void init() {
Button button = new Button("repaint");
add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Polylines.this.repaint();
}
});
}
public void paint(Graphics g) {
int arraySize = ((int)(Math.random()*100));
int[] xPoints = new int[arraySize];
int[] yPoints = new int[arraySize];
for(int i=0; i
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Polylines extends Applet {
private static Color[] colors = {
Color.white, Color.black, Color.blue, Color.red,
Color.yellow, Color.orange, Color.cyan, Color.pink,
Color.magenta, Color.green };
public void init() {
Button button = new Button("repaint");
add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Polylines.this.repaint();
}
});
}
public void paint(Graphics g) {
int arraySize = ((int)(Math.random()*100));
int[] xPoints = new int[arraySize];
int[] yPoints = new int[arraySize];
for(int i=0; i