1.在java中,怎么写关闭按钮事件.void java.awt.Window.dispose()
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
2.java中添加退出按钮你都会编这么多的代码了,怎么就剩下这两步不会?import java.awt.Button;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.Label;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class Round extends Frame implements ActionListener { TextField t1, t2, t3, t4; Button b1; Button btnExit; public Round() { setLayout(new FlowLayout()); t1 = new TextField(20); t1.setBackground(Color.orange); t2 = new TextField(20); t2.setBackground(Color.orange); t3 = new TextField(20); t3.setBackground(Color.orange); t4 = new TextField(20); t4.setBackground(Color.orange); b1 = new Button("计算"); btnExit = new Button("退出"); add(new Label("输入圆的半径:")); add(t1); add(new Label("得出圆的直径:")); add(t2); add(new Label("得出圆的面积:")); add(t3); add(new Label("得出圆的周长:")); add(t4); add(b1); add(btnExit); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); b1.addActionListener(this); btnExit.addActionListener(this); setVisible(true); setBounds(200, 200, 200, 300); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1){ double temp, r, a, c; temp = Float.parseFloat(t1.getText()); r = 2 * temp; a = 3.14 * temp * temp; c = 2 * 3.14 * temp; t2.setText(String.valueOf(r)); t3.setText(String.valueOf(a)); t4.setText(String.valueOf(c)); } if(e.getSource()==btnExit){ System.exit(0); } } public static void main(String args[]) { new Round(); }} 。
3.实现界面登陆,退出功能的java代码怎么写CS结构系统的退出如下:public void init() {
this.setTitle("用户登录界面");
this.add(createCenterPane());
this.(this.DO_NOTHING_ON_CLOSE);
this.setSize(new Dimension(450, 335));
this.setLocationRelativeTo(null);
// this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int choose = JOptionPane.showConfirmDialog(null,"是否要退出登录界面?",
"系统提示:",JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this为JFrame对象 。BS结构的退出直接用windows.close()方法就行了!
4.用java编写的自动按键如何退出问题在你的keypress处理中
while (true) {
// System.out.println(1);
if (e.getKeyCode() == KeyEvent.VK_F2) {
jfFrame.dispose();
}
if (e.getKeyCode() == KeyEvent.VK_F1)
try {
flash();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
当按下F1时,while循环将一直执行if( 。.= KeyEvent.VK_F1)内的代码,此时查看系统CPU一定会发现占用较高 。
同时,新的按键F2事件无法得到调用,因为CPU在忙着执行while的代码 。
改动的办法很简单,F5的触发就相当于是一个自动机,F1是触发F5的自动运行,F2是终止运行
只需要将F5触发的事件监听跟F2,F1都绑定到keypress函数中去,然后当检查到按键是F5时,则重新创建robot对象,延迟5秒触发keypress 。
改动代码如下:
public void keyPressed(KeyEvent e) {
//System.out.println(e.getKeyCode());
//while (true) { //删除
// System.out.println(1);
//追加F5的处理
if(e.getKeyCode() == KeyEvent.VK_F5){
- javaapi接口说明文档怎么写
- javashell脚本怎么写
- javamakefile怎么写
- java代码怎么写显示多个选择
- javawbe开发文档共享系统怎么写
- java程序员项目经验怎么写
- java打包jar路径怎么写
- javaservlet怎么写
- java简历怎么写啊
- javaweb怎么写网站api