Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 看看我的程序怎么了?(re: ActionListener)
billchang





发贴: 12
积分: 0
于 2005-10-07 09:42 user profilesend a private message to usersend email to billchangsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位好!我写过一些程序,总遇到个问题:一个button添加上ActionListener后,让它做些事情,但运行时,第一次点击它时,它没反应,第二次便执行了我所要做的事。但若在actionPerformed(ActionEvent e)中写上一句System.out.println("This is a applet.");则在DOS窗口会正常打印出This is a applet.点一次打印一次。下面是一个在applet中显示一张图片的程序,希望高手们运行一下。附件里有程序的所有内容。
//<applet code="PicApplet.class" height=400 width=400></applet>
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
/**
* <p>This is a applet for showing a picture.</p>
* <p>There is a button in the applet.</p>
* <p>It will show a picture when you click this button.</p>
*/
public class PicApplet extends Applet
implements ActionListener{
private Panel buttonPan = new Panel();
private Panel picPan = new Panel();
private Button showButton = new Button("Show");
public void init(){
setLayout(new BorderLayout());
buttonPan.add(showButton);
add(buttonPan,"South");
add(picPan,"Center");
showButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
//System.out.println("This is a applet.");
//You may modify a parameter when you want to change a picture.
Image img = getImage(getCodeBase(),"1.jpg");
picPan.getGraphics().drawImage(img,0,0,null);
}
}

PicApplet.rar (91.86k)


why edited on 2005-10-07 20:48

天行键,君子以自强不息!地势坤,君子以厚德载物!

话题树型展开
人气 标题 作者 字数 发贴时间
2811 看看我的程序怎么了?(re: ActionListener) billchang 1216 2005-10-07 09:42

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923