导航:首页 > 编程语言 > java按钮代码

java按钮代码

发布时间:2022-06-10 13:22:26

java刷新按钮的源代码

这好办
需要一个标志变量
例:必须是成员变量
静态的
static
int
flag
=
1;
下面是当刷新按钮事件出发时,判断flag的值
if(flag
==
1){
//执行按钮1的操作;
flag=2;
}else
if(flag
==
2){
//执行按钮2的操作;
flag=3;
}else
if(flag
==
3){
//执行按钮3的操作;
flag=4;
}else
if(flag
==
4){
//执行按钮4的操作;
flag=1;//设置为1,就可以循环刷新了
}

㈡ 那个,用java代码怎么写一个按钮事件

Button b = new Button();
b.setLabel("点击");
b.addMouseListener(new MouseListener(){
重写接口的方法
});

㈢ 用java写按钮和窗体的代码是什么

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class TestVerify {
public static void main(String[] args) {
new LoginFrame();
}

}

class LoginFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;

private JLabel nameLab;
private JLabel pwdLab;
private JButton confirmBtn;
private JTextField jtf_name;
private JPasswordField jtf_pwd;
private JButton resetBtn;

public LoginFrame() {
init();
}

public void init() {
setTitle("Login..");
setSize(260, 200);
setResizable(false);
setUndecorated(false);
//setAlwaysOnTop(true);

Toolkit tk = Toolkit.getDefaultToolkit();
setLocation((tk.getScreenSize().width - this.getWidth())/2,
(tk.getScreenSize().height - this.getHeight())/2);

//this.setLocationRelativeTo(null); //设置屏幕居中显示方法

//tk.setLockingKeyState(java.awt.event.KeyEvent.VK_NUM_LOCK, false); //设定num_lock键初始状态为锁定(键盘指示灯不亮)

nameLab = new JLabel("用户名:");
jtf_name = new JTextField(12);
pwdLab = new JLabel("密码:");
jtf_pwd = new JPasswordField(12);
confirmBtn = new JButton("确定");
resetBtn = new JButton("重置");

confirmBtn.addActionListener(this);
resetBtn.addActionListener(this);

JPanel jp_out = new JPanel();
JPanel jp_up = new JPanel();
JPanel jp_cen = new JPanel();
JPanel jp_down = new JPanel();

jp_up.setBounds(20, 20,200,30);
jp_up.add(nameLab);
jp_up.add(jtf_name);

jp_cen.setBounds(27, 50,200,30);;
jp_cen.add(pwdLab);
jp_cen.add(jtf_pwd);

jp_down.setBounds(30, 90,200,50);;
jp_down.add(confirmBtn);
jp_down.add(resetBtn);

jp_out.setLayout(null);
jp_out.add(jp_up,BorderLayout.NORTH);
jp_out.add(jp_cen,BorderLayout.CENTER);
jp_out.add(jp_down,BorderLayout.SOUTH);

add(jp_out);

setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand() == "确定") {
//System.out.println( JOptionPane.PLAIN_MESSAGE );
JOptionPane.showMessageDialog(this, "确定", "登陆提示。。。", JOptionPane.INFORMATION_MESSAGE);
}
if(e.getActionCommand() == "重置") {
jtf_name.setText("");
jtf_pwd.setText("");
}

}

/*public boolean verifyPassword(String name, String password) {

return false;
}*/

}

㈣ java中做一个按钮,点击按钮后画一个矩形的代码怎么写

兄弟帮你写了一个:

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

public class Print {
public static void main(String[] args) {
new Te();
}
}

class Te extends Frame implements ActionListener {

Color cc = Color.red;
int x = -20, y = -50;
Random r = new Random();

public Te() {

this.setLayout(null);
Button b = new Button("画圆");
this.add(b);
b.setBounds(30,30,50,50);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter () {

@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}

});
this.setBounds(200,200,500,400);
this.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
this.cc = Color.red;
this.x = r.nextInt(400);
do {
int x1 = r.nextInt(300);
this.y = x1;
} while (this.y < 50);

this.repaint();
}

@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(cc);
g.drawRect(x,y,50,50);
g.setColor(c);
}
}

㈤ java编程中按钮位置的代码

setLayoutManager(new BorderLayout());
然后像这样依次添加按钮:(具体添加到面板还是窗体由你自己决定了)
add(b1,BorderLayout.south)
add(b2,BorderLayout.north)
add(b3,BorderLayout.east)
add(b4,BorderLayout.west)
用了borderlayout之后,setbounds方法是无效的,可以删除这些冗余代码

㈥ java 按钮问题 用什么代码实现

JTabbedPane tabs = new JTabbedPane();
JPanel tab1= new JPanel();
tab1.setLayout(null);
tabs.add("主题",tab1);

JPanel tab2= new JPanel();
tab2.setLayout(null);
tabs.add("桌面",tab2);

JPanel tab3= new JPanel();
tab3.setLayout(null);
tabs.add("屏幕保护程序",tab3);

㈦ 在java中使用什么代码,可以使按钮具有打开目标文件夹的功能

打开文件

//打开工具的路径及名字

String toolsPath = "C:/WINDOWS/system32/notepad.exe ";

//被打开文件的路径及名字

String fileName = "test.txt";

try {

Runtime.getRuntime().exec(toolsPath+fileName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

打开文件夹

try {

String[] cmd = new String[5];

String url = "C:/input";

cmd[0] = "cmd";

cmd[1] = "/c";

cmd[2] = "start";

cmd[3] = " ";

cmd[4] = url;

Runtime.getRuntime().exec(cmd);

} catch (IOException e) {

e.printStackTrace();

}

或者

Runtime.getRuntime().exec("cmd /c start C:/input");

希望采纳

㈧ 一个窗体,一个按钮,最简单的java代码怎写

publicclassDemoextendsJFrame
{
JButtonjb;//一个按钮
publicstaticvoidmain(String[]args){
newDemo();
}
publicDemo()
{
this.setLayout(newFlowLayout());
jb=newJButton("按扭");
this.add(jb);
this.setSize(400,300);
this.setVisible(true);
this.setLocation(500,200);
}
}

㈨ JAVA的按纽代码的一点问题(BottonTest)如下

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonTest{
public static void main(String[] args){
ButtonFrame frame=new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ButtonFrame extends JFrame{
public ButtonFrame(){
setTitle("ButtonTest");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
ButtonPanel panel=new ButtonPanel();
add(panel);
}
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=200;
}
class ButtonPanel extends JPanel{
public ButtonPanel(){
JButton yellowButton=new JButton("Yellow");
JButton blueButton=new JButton("Blue");
JButton redButton=new JButton("Red");

add(yellowButton);
add(blueButton);
add(redButton);

ColorAction yellowAction=new ColorAction(Color.YELLOW,this);
ColorAction blueAction=new ColorAction(Color.BLUE,this);
ColorAction redAction=new ColorAction(Color.RED,this);

yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
}

class ColorAction implements ActionListener{
Color c;
ButtonPanel panel;
public ColorAction(Color c,ButtonPanel panel){
this.c=c;
this.panel=panel;
}

public void actionPerformed(ActionEvent event){
panel.setBackground(c);
}

}

㈩ Java中按钮事件代码

加入在frame中的按钮名为sure
Button sure=new Button("确定");
sure.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
frame1.setVisible(false);
Frame frame2=new Frame();
frame2.setVisible(true);

}
});

阅读全文

与java按钮代码相关的资料

热点内容
stc8单片机串口中断 浏览:954
信号分析pdf 浏览:927
暴力删除命令 浏览:803
qt如何编译加快速度 浏览:903
php添加数据sql语句 浏览:717
免费的小说app有什么 浏览:405
螺杆压缩机进气阀动画 浏览:651
两台服务器如何做负载均衡 浏览:227
程序员的工资是涨的吗 浏览:813
视频存储服务器可以干什么 浏览:463
创建文件夹安装失败怎么回事 浏览:832
程序员高考隔了几年 浏览:822
云服务器是哪一层 浏览:22
jit编译器的jit什么意思 浏览:330
我想清理手机中空白文件夹 浏览:976
电脑e盘文件夹删不掉怎么办 浏览:607
外圆凹圆弧编程 浏览:461
html5编程题 浏览:839
干燥机制冷压缩机一开就跳动 浏览:389
吉林压缩空气流量监测 浏览:618