[求助]555.我又来了。。(新问题)
import javax.swing.*;import java.awt.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
class GameDifficulty extends JFrame implements ChangeListener {
JPanel jp = new JPanel();
JPopupMenu jpm = new JPopupMenu();
JSlider js = new JSlider();
JTextField jtf = new JTextField();
public GameDifficulty() {
jp =(JPanel)this.getContentPane();
jp.setLayout(null);
jp.setBounds(0,0,400,300);
jpm.setBounds(0,0,400,300);
js.setBounds(100,50,200,60);
js.addChangeListener(this);
// js.setMaximum(100);
js.setMajorTickSpacing(30); //设置滑动条的最大间隔
js.setMinorTickSpacing(10); //设置滑动条的最小间隔
js.setPaintLabels(true); //显示数值标签
js.setPaintTicks(true); //显示最大及最小间隔条
js.setBounds(new Rectangle(40, 59, 216, 47));
jtf.setBounds(150,140,80,30);
// jp.add(jpm);弹出菜单不是这样添加的,所以我把它注释掉了
jp.add(js);
jp.add(jtf);
this.setSize(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//增加了点关闭时的操作,否则你点关闭的时候,你的程序并没有退出
}
public static void main(String [] args) {
new GameDifficulty();
}
public void stateChanged(ChangeEvent e) {
jtf.setText(""+js.getValue());
}
[此贴子已经被作者于2007-2-2 13:35:37编辑过]