java如何实现继续/暂停按钮 好像影音播放器的开始/暂停按钮一样,点击一下就切换成另外一个按钮了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用setLabel方法设置显示 开始还是暂停,响应点击事件的监听方法中 根据getLabel方法得到的不同结果设置不同的实现代码 boolean start = false;final JButton b = new JButton("start");b.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){b.setText(start ? "start" : "pause");start = ~start;}}) java没写过这样的程序用一个变量绑定这个按钮的状态,根据这个变量,觉得按下这个按钮要调用的处理函数..不知道这样行不行,以前在VC++中就这样做 SE好久没用了···不用大概思路可以告诉你参考一下加入开始是个button按钮写button的点击事件当你点击button的时候我先去得到button里面的值if(值是开始的话){我将你的button的值设置成 结束}else{我将你button里面的值设置成 开始} 要是做页面的效果其实还是换背景比较简单,可是你得用ajax查看当前状态。要是用两个按钮用隐藏做效果倒是不用管后台的执行状态。我倒是觉得你想让什么东西中断再执行可能和线程关系比较紧密。 你用个JToggleButton按钮有setPressedIcon(pressedIcon)方法,这样平时setIcon是不按的Icon,按下去就是另外一个图标 最终的解决方式是:使用了布局管理器,采用flowlayout的流布局方式把这两个空间放置在一个group中,然后把其中一个setvisible(false),由于布局是默认把不可见的控件的空间分配给可见的控件,这样一来就好像按钮重叠了一样~~不管怎么说,谢谢大家给了我其他的方法和创意! 导哪些包就不写了.public class Music {public Music{JLabel down;JLabel playandstop;JLabel up;playandstop = new JButton();playandstop.addActionListener(this);playandstop.setText("||>");playandstop.setBounds(50, 30, 60, 30);getContentPane().add(playandstop);down = new JButton();down.addActionListener(this);down.setText("< <");down.setBounds(145, 30, 60, 30);getContentPane().add(down);up = new JButton();up.addActionListener(this);up.setText("> >");up.setBounds(240, 30, 60, 30);getContentPane().add(up);public void actionPerformed(final ActionEvent e) { String flag = e.getActionCommand(); if (flag.equals("||>")) { playandstop.setText("| |"); } else if (flag.equals("| |")) { playandstop.setText("||>"); } } } 关于JFrame对象的 请大家帮忙 java 写文本文件 要提取这串内容的连接怎么有问题? 请问swing的程序运行特别慢是怎么回事? 遇到问题:文件下载的时候,弹出下载对话框,但是“打开”要按2次才能打开文件。 用JAVA有什么前途??有什么主向?? 类型转换 JAVA大概要多长时间才能上手? 请问JAVA多线程实现一边。。。一边。。。大概的思路是什么? 请教个正则问题 如何解密百度mp3音乐的下载地址链接而获得真实的链接 Java中 BufferedImage 复制问题
final JButton b = new JButton("start");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
b.setText(start ? "start" : "pause");
start = ~start;
}
})
加入开始是个button按钮
写button的点击事件
当你点击button的时候我先去得到button里面的值
if(值是开始的话){
我将你的button的值设置成 结束
}else{
我将你button里面的值设置成 开始
}
不管怎么说,谢谢大家给了我其他的方法和创意!
JLabel down;
JLabel playandstop;
JLabel up;playandstop = new JButton();
playandstop.addActionListener(this);
playandstop.setText("||>");
playandstop.setBounds(50, 30, 60, 30);
getContentPane().add(playandstop);down = new JButton();
down.addActionListener(this);
down.setText("< <");
down.setBounds(145, 30, 60, 30);
getContentPane().add(down);up = new JButton();
up.addActionListener(this);
up.setText("> >");
up.setBounds(240, 30, 60, 30);
getContentPane().add(up);public void actionPerformed(final ActionEvent e) {
String flag = e.getActionCommand();
if (flag.equals("||>")) {
playandstop.setText("| |");
} else if (flag.equals("| |")) {
playandstop.setText("||>");
}
}
}