import java.awt.*;
import java.awt.event.*;
public class Interact implements ActionListener {
Frame f=new Frame("按钮交互事件");
f.setLayout(new FlowLayout());//此处出现提示错误。
Button b=new Button("打开");
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==b)
{ if(b.getLabel()=="打开")
{ b.setLabel("关闭");
f.pack();
}
else
{b.setLabel("打开"); f.pack();}
}
我想作一个按钮交互的图像,看看上面的程序怎么改呀。
}
}
import java.awt.event.*;
public class Interact implements ActionListener {
Frame f=new Frame("按钮交互事件");
f.setLayout(new FlowLayout());//此处出现提示错误。
Button b=new Button("打开");
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==b)
{ if(b.getLabel()=="打开")
{ b.setLabel("关闭");
f.pack();
}
else
{b.setLabel("打开"); f.pack();}
}
我想作一个按钮交互的图像,看看上面的程序怎么改呀。
}
}
解决方案 »
- LRESULT CExample1Dlg::OnServerMessage(WPARAM wParam, LPARAM lParam)
- 如何在一个页面上显示多个jfreechart的图像啊
- 关于ibatis的一些问题
- 在用netbeans进行单元测试是,为什么总是有“测试案例为原型”测试不成功?
- Java里有什么方法可以实现预处理吗? 请高手告之!!!
- 谁能提供一套完整的Java系统的源程序?收到后加100分。
- 三台机子间互相栲文件,如何实现最好?
- 帮忙解决一个有趣的正则表达式,先谢了!
- java新手,求前辈大神们指导(java 函数参数传递的疑惑)
- 我刚学Java,用Javac编译一个例程没问题,但一用Java运行就出错:Exception in the thread "main" java.lang.NoClassDefFoundError: Welcome
- 非技术区没人气,放这里来![散分]还有2个问题!
- 字符的显示
import java.awt.event.*;public class Interact implements ActionListener { public static void main(String[] args) {
Frame frame=new Frame("按钮交互事件");
frame.setLayout(new FlowLayout());
frame.setSize(200, 100);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Button cmd=new Button("打开");
cmd.addActionListener(new Interact());
frame.add(cmd);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("打开")){
((Button)e.getSource()).setLabel("关闭");
}else{
((Button)e.getSource()).setLabel("打开");
}
}
}