关于java后台按钮开关的信息
今天给各位分享java后台按钮开关的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java 怎样实现点击按钮,关闭程序?
- 2、java后台怎么控制点击一个按钮,按钮变灰不可用,且刷新页面也不变
- 3、java设置关闭窗口按钮
- 4、java的开关按钮JToggleButton,如何获取开关按钮的宽度和高度?
- 5、JAVA如何用按钮关闭窗体
- 6、JAVA中怎么实现按钮功能?
java 怎样实现点击按钮,关闭程序?
给按钮添加 ActionPerform 事件 内容写System.exit(0);
package com.lx;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Test implements ActionListener {
Frame f = new Frame();
public static void main(String[] args) {
Test t = new Test();
t.init();
}
private void init() {
Button b = new Button("exit");
b.addActionListener(this);
f.add(b);
f.setLayout(new FlowLayout());
f.setSize(100,100);
f.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
f.setVisible(false);
f.dispose();
System.exit(0);
}
}
java后台怎么控制点击一个按钮,按钮变灰不可用,且刷新页面也不变
input id=xxx type=button value="点我不会变亮"
script
document.getElementById("xxx").disabled=true;
/script
如果你的按钮点击后会变亮,那你的代码肯定有问题的,要看到你的代码才知道原因。
java设置关闭窗口按钮
package org.t20110219.test;
/**
* 修改后的代码
* 能关闭,
* 希望能帮助你
*/
import java.awt.*;
import java.awt.event.*;
public class MainProgram extends Frame implements ActionListener,WindowListener
{
int i;
Button b1 = new Button("确定");
Button b2 = new Button("关闭");
void FlowLayoutEX()
{
this.setTitle("布局管理器");
this.setLayout(new FlowLayout());
this.add(b1);
b1.addActionListener(this);
this.add(b2);
b2.addActionListener(this);
this.addWindowListener(this);
this.setBounds(100, 100, 250, 250);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/**------------修改代码--------------*/
/**
* 修改 合理就可以了
* e.getSource() 可以得到 你点击了哪个 按钮
* 判断之后就可以 设定 对应的 操作了
*/
if(e.getSource()==b2){
System.exit(0);
}else{
i++;
Button bi = new Button("按钮"+i);
this.add(bi);
this.show(true);
}
}
public void windowClosing(WindowEvent f)
{
System.exit(0);
}
public void windowOpened(WindowEvent f){}
public void windowClosed(WindowEvent f){}
public void windowIconified(WindowEvent f){}
public void windowDeiconified(WindowEvent f){}
public void windowActivated(WindowEvent f){}
public void windowDeactivated(WindowEvent f){}
public static void main(String args[])
{
MainProgram window = new MainProgram();
window.FlowLayoutEX();
}
}
java的开关按钮JToggleButton,如何获取开关按钮的宽度和高度?
JToggleButton button = new JToggleButton("开关按钮");
int width = button.getWidth();
int height = button.getHeight();
JAVA如何用按钮关闭窗体
很久没有用过界面编程了,就当复习一下了,哈哈
如一楼所说的,给按钮加一个监听器ActionListener,写一个实现方法
actionPerformed.此时当按钮点击时会调用actionPerformed方法,代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Close extends JFrame implements ActionListener{
JButton close;
public Close(){
close = new JButton("close");//增加一个按钮
add(close);
close.addActionListener(this);//给按钮增加一个监听器
setLayout(new FlowLayout());
setSize(200,100);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//捕捉到按钮点击时的事件处理方法
//按钮点击时一定会自动执行actionPerformed(ActionEvent e)方法
public void actionPerformed(ActionEvent e){
//关闭整个应用程序.如果只是是想关闭当前窗口,可以用
//dispose();
System.exit(0);
}
public static void main(String[] args){
new Close();
}
}
JAVA中怎么实现按钮功能?
使用图形用户界面
class Gui extends JFrame implements ActionListener {
private JButton jb = new JButton() ;
Gui() {
super("Gui") ;
this.add(jb) ;//添加按钮
jb.addActionListener(this) ;//按钮事件监听
//当然你可以按自己的想法做布局
this.pack();
this.setVisible(true);//可见
this.setResizable(false);//不可修改大小
this.setLocation(100, 100);//起始位置
}
//覆写ActionListener接口中的事件处理方法
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb) {
//事件处理
}
}
}
java后台按钮开关的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java后台按钮开关的信息别忘了在本站进行查找喔。