在我的应用程序中,我创建了一个数组来控制输出中的标志图像。这工作正常,但是当我从数组中删除一个元素时,图片根本没有变化。
class Flag{
Image FlagImage;
int FlagNum = 0;
public Flag(int FlagNum) {
this.FlagNum = FlagNum;
try{
FlagImage = ImageIO.read(new File("flag1.png"));
}catch(Exception e){
}
}
public void Update() {
}
public void Draw(Graphics g) {
//Draw Flag
g.drawImage(FlagImage, ((FlagNum) % 3+1) * 100-100, (int)((FlagNum) / 3) * 100+100, null);
}
}
public class Flags extends JPanel {
/**
* Creates new form Flags
*/
public Flags(){
initComponents();
FlagSet.add(new Flag(1));
final Timer timer =new Timer(10, new ActionListener(){
@Override
public void actionPerformed(final ActionEvent e){
repaint();
for (Flag f: FlagSet){
f.Update();
}
}
});
}
public static ArrayList<Flag> FlagSet = new ArrayList();
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
for (Flag f: FlagSet){
f.Draw(g);
}
}
然后我尝试添加这样的标志:
flagCounter = 4;
while(flagCounter > -1){
Flags.FlagSet.add(new Flag(flagCounter));
flagCounter--;
}
哪个工作正常,但如果我稍后加入Flgas.FlageSet.remove(//Some flag)
,我的图片就不会改变。有任何想法吗?提前谢谢。
答案 0 :(得分:2)
您似乎错过了对<?php
?>
<script type="text/javascript">
function sendLog(){
tosend = [
'**Server added;**',
'Game Name: <?php echo(json_encode($name)); ?>',
'Game ID: <?php echo(json_encode($gid)); ?>',
'Server ID: <?php echo(json_encode($sid)); ?>',
],
msgJson = {
"attachments": [
{
"color": "#CC09EF",
"text": tosend.join('\n'),
"footer": "Infius Game Logs",
"footer_icon": "http://deersystems.net/assets/images/nfius.png",
}
]
}
post(hookurl, msgJson);
}
function post(url, jsonmsg){
xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
var data = JSON.stringify(jsonmsg);
xhr.send(data);
xhr.onreadystatechange = function() {
if(this.status != 200){
alert("ttt");
}
}
}
</script>
<?php
if($token == '*****'){
$con = mysqli_connect("localhost","8888888");
if(mysqli_connect_errno()){
echo(mysqli_connect_error());
}
} elseif($type == 'add' and $sid !=NULL and $gid !=NULL and $name!=NULL and $players !=NULL){
?>
<script type="text/javascript">
sendLog();
</script>
<?php
} else {
echo"<script type=\"text/javascript\">
sendLog();
</script>";
}
?>
的调用。
重绘是发送到绘图组件的信号,告诉它某些内容已发生变化,并且需要再次调用repaint()
方法。在这种情况下,由于您对paint
列表的添加会改变其显示方式,因此您只需在完成添加标记后致电Flags
。